Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent map element types - defaults inside optional object #32157

Closed
liamcervante opened this issue Nov 3, 2022 · 3 comments · Fixed by #32178
Closed

inconsistent map element types - defaults inside optional object #32157

liamcervante opened this issue Nov 3, 2022 · 3 comments · Fixed by #32178
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v1.3 Issues (primarily bugs) reported against v1.3 releases

Comments

@liamcervante
Copy link
Member

liamcervante commented Nov 3, 2022

Terraform Version

1.3.4

Terraform Configuration Files

variable "domains" {
  type = map(object({
    rules = map(object({
      backend = optional(string)
      url_redirect = optional(object({
        destination   = string
        preserve_path = optional(bool, true)
      }))
    }))
  }))
}
domains = {
  "one" = {
    rules = {
      "/" = {
        "backend" = "testing"
      }
    }
  }

  "two" = {
    rules = {
      "/" = {
        url_redirect = {
            destination   = "https://redirect.fake.domain.com/alertmanager"
            preserve_path = false
        }
      }
    }
  }
}

Debug Output

n/a

Expected Behavior

no crash

Actual Behavior

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!


inconsistent map element types (cty.Object(map[string]cty.Type{"rules":cty.Map(cty.Object(map[string]cty.Type{"backend":cty.String, "url_redirect":cty.Object(map[string]cty.Type{"preserve_pa
th":cty.Bool})}))}) then cty.Object(map[string]cty.Type{"rules":cty.Map(cty.Object(map[string]cty.Type{"backend":cty.String, "url_redirect":cty.Object(map[string]cty.Type{"destination":cty.S
tring, "preserve_path":cty.Bool})}))}))
goroutine 55 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x64
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x1c
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /Users/distiller/project/project/internal/logging/panic.go:55 +0x170
panic({0x1025d5500, 0x140005be980})
        /usr/local/go/src/runtime/panic.go:884 +0x204
github.com/zclconf/go-cty/cty.MapVal(0x14000634ed8)
        /Users/distiller/go/pkg/mod/github.com/zclconf/[email protected]/cty/value_init.go:221 +0x488
github.com/zclconf/go-cty/cty.transform({0x0?, 0x0, 0x0}, {{{0x1029da648?, 0x140005be640?}}, {0x10260db00?, 0x140005c0cf0?}}, {0x1029c1a80, 0x14000556178})
        /Users/distiller/go/pkg/mod/github.com/zclconf/[email protected]/cty/walk.go:204 +0x92c
github.com/zclconf/go-cty/cty.TransformWithTransformer(...)
        /Users/distiller/go/pkg/mod/github.com/zclconf/[email protected]/cty/walk.go:130
github.com/hashicorp/hcl/v2/ext/typeexpr.(*Defaults).Apply(0x1400083f840?, {{{0x1029da648?, 0x140005be640?}}, {0x10260db00?, 0x140005c0cf0?}})
        /Users/distiller/go/pkg/mod/github.com/hashicorp/hcl/[email protected]/ext/typeexpr/defaults.go:38 +0x9c
github.com/hashicorp/terraform/internal/terraform.prepareFinalInputVariableValue({{0x0, 0x0, 0x0}, {{}, {0x1400055c180, 0x7}}}, 0x1400042ee70, 0x1400097b6c0)
        /Users/distiller/project/project/internal/terraform/eval_variable.go:140 +0x854
github.com/hashicorp/terraform/internal/terraform.(*NodeRootVariable).Execute(0x1400083fb80, {0x1029eea38, 0x140006380e0}, 0xc0?)
        /Users/distiller/project/project/internal/terraform/node_root_variable.go:82 +0x168
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0x1400027ec30, {0x1029eea38, 0x140006380e0}, {0x12beff8f8, 0x1400083fb80})
        /Users/distiller/project/project/internal/terraform/graph_walk_context.go:136 +0xa8
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x102744f20, 0x1400083fb80})
        /Users/distiller/project/project/internal/terraform/graph.go:74 +0x208
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0x14000705140, {0x102744f20, 0x1400083fb80}, 0x1400090fb00)
        /Users/distiller/project/project/internal/dag/walk.go:381 +0x2e0
created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update
        /Users/distiller/project/project/internal/dag/walk.go:304 +0xbf0

Steps to Reproduce

terraform init
terraform apply

Additional Context

No response

References

#32152

@liamcervante liamcervante added bug confirmed a Terraform Core team member has reproduced this issue v1.3 Issues (primarily bugs) reported against v1.3 releases labels Nov 3, 2022
@liamcervante liamcervante self-assigned this Nov 3, 2022
@liamcervante
Copy link
Member Author

liamcervante commented Nov 3, 2022

This is an issue in the HCL defaults package. Essentially it tries to create a value for preserve_path inside the non-existent url_redirect object in the first entry in the map. Since destination does not have a default value it creates an object of the wrong type, and then when it tries reconcile the surrounding map with the new default values we get the crash due to inconsistent types (one object has both destination and preserve_path while the other only has preserve_path).

I think the correct behaviour here would be to just leave the whole url_redirect object as null and not attempt to insert default values into null objects.

@liamcervante
Copy link
Member Author

A workaround for this is to provide an default value for the destination field as well as the preserve_path field OR to provide a default value for the whole url_redirect object.

This is still a bug, but you might be able to make progress with the workaround until we can fix it.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v1.3 Issues (primarily bugs) reported against v1.3 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant