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

Terraform[1] - inconsistent list element types #32048

Closed
enchorb opened this issue Oct 20, 2022 · 2 comments
Closed

Terraform[1] - inconsistent list element types #32048

enchorb opened this issue Oct 20, 2022 · 2 comments
Labels
bug duplicate issue closed because another issue already tracks this problem

Comments

@enchorb
Copy link

enchorb commented Oct 20, 2022

Terraform Version

Terraform v1.3.3
on linux_amd64 

Debug Output

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

Terraform crashed! This is always indicative of a bug within Terraform.
Please report the crash with Terraform[1] 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.

[1]: https://github.com/hashicorp/terraform/issues

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

inconsistent list element types (cty.Object(map[string]cty.Type{"ack_deadline_seconds":cty.String, "enable_exactly_once_delivery":cty.Bool, "enable_message_ordering":cty.Bool, "expiration_days":cty.Number, "message_retention_duratio
n":cty.Number, "name":cty.String, "push_endpoint":cty.String, "retain_acked_messages":cty.Bool}) then cty.Object(map[string]cty.Type{"ack_deadline_seconds":cty.String, "enable_exactly_once_delivery":cty.Bool, "enable_message_orderin
g":cty.Bool, "expiration_days":cty.String, "message_retention_duration":cty.Number, "name":cty.String, "push_endpoint":cty.String, "retain_acked_messages":cty.Bool}))
module.server.google_cloud_run_domain_mapping.server["doots"]: Refreshing state... [id=locations/us-central1/namespaces/earthone-dev/domainmappings/doots.earthone.dev]
goroutine 3633 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x19
github.com/hashicorp/terraform/internal/logging.PanicHandler()
        /home/circleci/project/project/internal/logging/panic.go:55 +0x153
panic({0x21e01a0, 0xc004962c30})
        /usr/local/go/src/runtime/panic.go:884 +0x212
github.com/zclconf/go-cty/cty.ListVal({0xc004cd1200, 0x2, 0x1?})
        /home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.11.1/cty/value_init.go:166 +0x42e
github.com/zclconf/go-cty/cty.transform({0x0?, 0x0, 0x0}, {{{0x2b669d0?, 0xc0049627e0?}}, {0x20ef040?, 0xc004948888?}}, {0x2b4dda0, 0xc0008d43d0})
        /home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.11.1/cty/walk.go:175 +0xf4a
github.com/zclconf/go-cty/cty.TransformWithTransformer(...)
        /home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.11.1/cty/walk.go:130
github.com/hashicorp/hcl/v2/ext/typeexpr.(*Defaults).Apply(0xc001061ae0?, {{{0x2b669d0?, 0xc0049627e0?}}, {0x20ef040?, 0xc004948888?}})
        /home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.14.1/ext/typeexpr/defaults.go:38 +0xa7
github.com/hashicorp/terraform/internal/terraform.prepareFinalInputVariableValue({{0xc0065980e0, 0x1, 0x1}, {{}, {0xc000ccbb60, 0xb}}}, 0xc000fe1a58, 0xc00067e1a0)
        /home/circleci/project/project/internal/terraform/eval_variable.go:98 +0xacd
github.com/hashicorp/terraform/internal/terraform.(*nodeModuleVariable).evalModuleVariable(0xc0008946c0?, {0x2b7ceb8?, 0xc0063be0e0?}, 0x1d?)
        /home/circleci/project/project/internal/terraform/node_module_variable.go:239 +0x545
github.com/hashicorp/terraform/internal/terraform.(*nodeModuleVariable).Execute(0xc0008946c0, {0x2b7ceb8, 0xc0063be0e0}, 0x2)
        /home/circleci/project/project/internal/terraform/node_module_variable.go:155 +0x172
github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc001ac34a0, {0x2b7ceb8, 0xc0063be0e0}, {0x7f44e759b888, 0xc0008946c0})
        /home/circleci/project/project/internal/terraform/graph_walk_context.go:136 +0xc2
github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x23aebe0, 0xc0008946c0})
        /home/circleci/project/project/internal/terraform/graph.go:74 +0x2f0
github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc000894780, {0x23aebe0, 0xc0008946c0}, 0xc004cd0ec0)
        /home/circleci/project/project/internal/dag/walk.go:381 +0x2f6
created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update
        /home/circleci/project/project/internal/dag/walk.go:304 +0xf65

Expected Behavior

No crash with any optional attribute

Actual Behavior

Additional context provided in code sample below.

Using a list of object with optional attributes will cause a crash if the optional attribute isn't a string or bool and is missing from any element of the list.

What is currently causing the crash is expiration_days since it is an optional attribute of type number and isn't present on all elements of the list of objects. If I was to turn it into a string (optional(string, "31")) and re-run apply then it wouldn't crash.

A crash also happened when I tried to turn the type to any.

Additional Context

main.tf

  topics = [
    {
      name = "test"
      subscribers = [
        {
          name                 = "pull"
          ack_deadline_seconds = 120
        },
        {
          name                 = "push"
          push_endpoint        = "https://test.com/test"
          ack_deadline_seconds = 30
          expiration_days      = 4
        }
      ]
    }
  ]

module "pubsub" {
  for_each    = { for topic in local.topics : topic.name => topic }
  source      = "./modules/pubsub"
  name        = each.value.name
  subscribers = coalesce(each.value.subscribers, [])
}

pubsub variables.tf

variable "subscribers" {
  type = list(object({
    name                         = string
    ack_deadline_seconds         = optional(number, 10)
    message_retention_duration   = optional(number, 604800)
    expiration_days              = optional(number, 31)
    retain_acked_messages        = optional(bool, false)
    enable_message_ordering      = optional(bool, false)
    enable_exactly_once_delivery = optional(bool, false)
    push_endpoint                = optional(string, null)
  }))
  description = "List of subscribers to pubsub topic"
  default     = []
}

Steps to Reproduce

terraform init
terraform apply

References

#31978
This might be related? #32033

@enchorb enchorb added bug new new issue not yet triaged labels Oct 20, 2022
@jbardin jbardin added the duplicate issue closed because another issue already tracks this problem label Oct 20, 2022
@jbardin
Copy link
Member

jbardin commented Oct 20, 2022

Duplicate of #31978

@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 Nov 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug duplicate issue closed because another issue already tracks this problem
Projects
None yet
Development

No branches or pull requests

3 participants