-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Terraform crash with nested optional default values #32152
Comments
Hi @danischm, thanks for the report and for the easy to reproduce config files. I can confirm that I can reproduce this, we'll take a look to see about potential fixes and the root cause. |
The root cause for this is within the go-cty downstream dependency via the hcl dependency. HCL initially reads in the default value for the list as a tuple, and then converts it into a list using the go-cty conversion functions. Historically the conversion functions have not dealt consistently with optional attributes, and the tuple to list function is missing some recent fixes which result in the default value for the "def" object and the provided value for the "abc" object having different optional metadata. Then we see the crash when HCL attempts to combine these objects into a list have they have different types. We'll need to do another pass over go-cty to fix the conversion functions, and then update the dependency in HCL, and then update Terraform with new versions of HCL and go-cty. |
I can confirm we're experiencing the same with a similar configuration: variable "domains" {
type = map(object({
rules = map(object({
backend = optional(string)
url_redirect = optional(object({
destination = string
preserve_path = optional(bool, true)
}))
}))
}))
} Output:
|
Hi @claudioscalzo - can you share some more information about how you are using that variable? Or what value you are giving it that causes the crash? I can't reproduce your crash just with that variable, and I'd like to check it's the same root cause and that my fix works for this locally as well. Thanks! |
Hi @liamcervante - Sure! Here's a full configuration (working on
module "fake_module" {
source = "./fake-module"
domains = {
"domain-1" = {
rules = {
"/" = {
backend = "backend-a"
}
}
}
"domain-2" = {
rules = {
"/" = {
url_redirect = {
destination = "https://redirect.fake.domain.com/alertmanager"
preserve_path = false
}
}
}
}
}
}
variable "domains" {
type = map(object({
rules = map(object({
backend = optional(string)
url_redirect = optional(object({
destination = string
preserve_path = optional(bool, true)
}))
}))
}))
} |
Hi @claudioscalzo, thanks for that. I've investigated and I think it has a different root cause to this issue. I've filed a new issue linked above, and included a potential workaround for you in the comments there. I haven't been able to find a workaround for this issue yet. |
Hi @liamcervante - Thanks for the investigation and the workarounds you proposed. Currently, we decided to pin the Hoping for a fix, thanks for the quick response to the issue! |
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. |
Terraform Version
Terraform Configuration Files
https://github.com/danischm/tf-nested-optional-crash
Debug Output
!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform1 so that we can fix this.
When reporting bugs, please include your terraform version, the stack trace
shown below, and any additional information which may help replicate the issue.
!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
inconsistent list element types (cty.Object(map[string]cty.Type{"optional_list":cty.List(cty.Object(map[string]cty.Type{"optional_string":cty.String, "string":cty.String})), "string":cty.String}) then cty.Object(map[string]cty.Type{"optional_list":cty.List(cty.ObjectWithOptionalAttrs(map[string]cty.Type{"optional_string":cty.String, "string":cty.String}, []string{"optional_string"})), "string":cty.String}))
goroutine 16 [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({0x104479500, 0x1400021e0c0})
/usr/local/go/src/runtime/panic.go:884 +0x204
github.com/zclconf/go-cty/cty.ListVal({0x1400078e3c0, 0x2, 0x1?})
/Users/distiller/go/pkg/mod/github.com/zclconf/go-cty@v1.12.0/cty/value_init.go:166 +0x454
github.com/zclconf/go-cty/cty.transform({0x0?, 0x0, 0x0}, {{{0x10487e610?, 0x1400033c7a0?}}, {0x104387a20?, 0x140007ccff0?}}, {0x104865a80, 0x140007c8318})
/Users/distiller/go/pkg/mod/github.com/zclconf/go-cty@v1.12.0/cty/walk.go:175 +0xb9c
github.com/zclconf/go-cty/cty.TransformWithTransformer(...)
/Users/distiller/go/pkg/mod/github.com/zclconf/go-cty@v1.12.0/cty/walk.go:130
github.com/hashicorp/hcl/v2/ext/typeexpr.(*Defaults).Apply(0x14000576a60?, {{{0x10487e610?, 0x1400033c7a0?}}, {0x104387a20?, 0x140007ccff0?}})
/Users/distiller/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.14.1/ext/typeexpr/defaults.go:38 +0x9c
github.com/hashicorp/terraform/internal/terraform.prepareFinalInputVariableValue({{0x0, 0x0, 0x0}, {{}, {0x14000264178, 0x4}}}, 0x14000431030, 0x140005c5d40)
/Users/distiller/project/project/internal/terraform/eval_variable.go:140 +0x854
github.com/hashicorp/terraform/internal/terraform.(*NodeRootVariable).Execute(0x140008627c0, {0x104892a38, 0x140002b0700}, 0xc0?)
/Users/distiller/project/project/internal/terraform/node_root_variable.go:82 +0x168
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0x14000860000, {0x104892a38, 0x140002b0700}, {0x12dbe7d38, 0x140008627c0})
/Users/distiller/project/project/internal/terraform/graph_walk_context.go:136 +0xa8
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x1045e8f20, 0x140008627c0})
/Users/distiller/project/project/internal/terraform/graph.go:74 +0x208
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0x1400085d980, {0x1045e8f20, 0x140008627c0}, 0x1400078e180)
/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
Expected Behavior
no crash
Actual Behavior
crash
Steps to Reproduce
terraform apply
Additional Context
Removing the default value
[]
in line 7 main.tf fixes the crash. A git bisect revealed the following 'bad' commit: 6521355References
No response
The text was updated successfully, but these errors were encountered: