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

setproduct panics #28984

Closed
tbugfinder opened this issue Jun 18, 2021 · 6 comments · Fixed by #28994
Closed

setproduct panics #28984

tbugfinder opened this issue Jun 18, 2021 · 6 comments · Fixed by #28994
Labels
bug confirmed a Terraform Core team member has reproduced this issue crash explained a Terraform Core team member has described the root cause of this issue in code functions upstream v1.0 Issues (primarily bugs) reported against v1.0 releases

Comments

@tbugfinder
Copy link

tbugfinder commented Jun 18, 2021

Terraform Version

]$ terraform -version
Terraform v1.0.0
on linux_amd64

and 
$ terraform version
Terraform v0.15.3
on linux_amd64


...

Terraform Configuration Files

locals {
  availability_zones_short = toset([substr(data.aws_availability_zones.available.names[0], -2, -1), substr(data.aws_availability_zones.available.names[1], -2, -1)])
  natgw_keys               = toset([for k in local.availability_zones_short : "natgw-${k}"])
  onprem_cidr_blocks = toset(["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16" ])
}

data "aws_availability_zones" "available" {
  state = "available"
}

output "setproduct" {
  value = setproduct(local.natgw_keys, local.onprem_cidr_blocks)
}

Debug Output

[2021-06-18T16:35:43.369Z] $$$$$$ Validating the Terraform configuration files...
[2021-06-18T16:35:47.499Z]        
[2021-06-18T16:35:47.499Z]        Error: Error in function call
[2021-06-18T16:35:47.499Z]        
[2021-06-18T16:35:47.499Z]          on ../../../main.tf line 257, in resource "aws_route" "natgw_onprem":
[2021-06-18T16:35:47.499Z]         257:     for pair in setproduct(local.natgw_keys, local.onprem_cidr_blocks) : "${pair[0]}_${pair[1]}" => {
[2021-06-18T16:35:47.499Z]            ├────────────────
[2021-06-18T16:35:47.499Z]            │ local.natgw_keys is set of string with 2 elements
[2021-06-18T16:35:47.499Z]            │ local.onprem_cidr_blocks is set of string with 7 elements
[2021-06-18T16:35:47.499Z]        
[2021-06-18T16:35:47.499Z]        Call to function "setproduct" failed: panic in function implementation:
[2021-06-18T16:35:47.499Z]        runtime error: hash of unhashable type cty.ValueMarks
[2021-06-18T16:35:47.499Z]        goroutine 356 [running]:
[2021-06-18T16:35:47.499Z]        runtime/debug.Stack(0xc0022af3a8, 0x247fb40, 0xc002659d10)
[2021-06-18T16:35:47.499Z]        	/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
[2021-06-18T16:35:47.499Z]        github.com/zclconf/go-cty/cty/function.errorForPanic(...)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/function/error.go:44
[2021-06-18T16:35:47.499Z]        github.com/zclconf/go-cty/cty/function.Function.Call.func1(0xc0022afb60,
[2021-06-18T16:35:47.499Z]        0xc0022afb80)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/function/function.go:291
[2021-06-18T16:35:47.499Z]        +0x93
[2021-06-18T16:35:47.499Z]        panic(0x247fb40, 0xc002659d10)
[2021-06-18T16:35:47.499Z]        	/usr/local/go/src/runtime/panic.go:965 +0x1b9
[2021-06-18T16:35:47.499Z]        github.com/zclconf/go-cty/cty.Value.Mark(0x2cb97b0, 0xc002659cf0, 0x24341a0,
[2021-06-18T16:35:47.499Z]        0x3dafde0, 0x252f520, 0x0, 0x24341a0, 0x3dafde0, 0x0, 0xc00073ee10)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/marks.go:208
[2021-06-18T16:35:47.499Z]        +0x1dc
[2021-06-18T16:35:47.499Z]        github.com/zclconf/go-cty/cty/function/stdlib.glob..func33(0xc0026fbdc0, 0x2,
[2021-06-18T16:35:47.499Z]        0x2, 0x2cb97b0, 0xc002659cf0, 0xc002659cf0, 0x0, 0x0, 0x3db02e8, 0x40dc01,
[2021-06-18T16:35:47.499Z]        ...)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/function/stdlib/collection.go:948
[2021-06-18T16:35:47.499Z]        +0x119a
[2021-06-18T16:35:47.499Z]        github.com/zclconf/go-cty/cty/function.Function.Call(0xc00004dd10,
[2021-06-18T16:35:47.499Z]        0xc0026fbdc0, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/zclconf/go-cty@v1.8.3/cty/function/function.go:295
[2021-06-18T16:35:47.499Z]        +0x4a7
[2021-06-18T16:35:47.499Z]        github.com/hashicorp/hcl/v2/hclsyntax.(*FunctionCallExpr).Value(0xc0003a3a40,
[2021-06-18T16:35:47.499Z]        0xc00288e0c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
[2021-06-18T16:35:47.499Z]        	/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.10.0/hclsyntax/expression.go:442
[2021-06-18T16:35:47.499Z]        +0xff6
[2021-06-18T16:35:47.499Z]        github.com/hashicorp/hcl/v2/hclsyntax.(*ForExpr).Value(0xc00089de00,
[2021-06-18T16:35:47.499Z]        0xc00288e0c0, 0x0, 0xc0022b1500, 0x1, 0x1, 0x0, 0x0, 0x0)
[2021-06-18T16:35:47.500Z]        	/home/circleci/go/pkg/mod/github.com/hashicorp/hcl/v2@v2.10.0/hclsyntax/expression.go:993
[2021-06-18T16:35:47.500Z]        +0x59
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.evaluateForEachExpressionValue(0x7fa7fb02b9d8,
[2021-06-18T16:35:47.500Z]        0xc00089de00, 0x2cf0800, 0xc0007dc1c0, 0x1, 0x397377612d746e69,
[2021-06-18T16:35:47.500Z]        0x3835333036353138, 0x7365742d77662d6f, 0x6c75616665642d74,
[2021-06-18T16:35:47.500Z]        0x2e6c61636f6c2e74, ...)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/eval_for_each.go:59 +0x33a
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.validateForEach(0x2cf0800,
[2021-06-18T16:35:47.500Z]        0xc0007dc1c0, 0x7fa7fb02b9d8, 0xc00089de00, 0x1, 0x1, 0x0)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/node_resource_validate.go:461
[2021-06-18T16:35:47.500Z]        +0x6c
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.(*NodeValidatableResource).validateResource(0xc00070c0f8,
[2021-06-18T16:35:47.500Z]        0x2cf0800, 0xc0007dc1c0, 0xc0000cbc50, 0x405c88, 0xc000e76058)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/node_resource_validate.go:302
[2021-06-18T16:35:47.500Z]        +0x1d6a
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.(*NodeValidatableResource).Execute(0xc00070c0f8,
[2021-06-18T16:35:47.500Z]        0x2cf0800, 0xc0007dc1c0, 0xc06104, 0xc0000cbce8, 0x40bb05, 0x24aa5e0)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/node_resource_validate.go:41
[2021-06-18T16:35:47.500Z]        +0x5a
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc0009d4680,
[2021-06-18T16:35:47.500Z]        0x2cf0800, 0xc0007dc1c0, 0x7fa7fb3c3420, 0xc00070c0f8, 0x0, 0x0, 0x0)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/graph_walk_context.go:129
[2021-06-18T16:35:47.500Z]        +0xbf
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1(0x27ba020,
[2021-06-18T16:35:47.500Z]        0xc00070c0f8, 0x0, 0x0, 0x0)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/terraform/graph.go:59 +0xbd3
[2021-06-18T16:35:47.500Z]        github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc0000ff7a0,
[2021-06-18T16:35:47.500Z]        0x27ba020, 0xc00070c0f8, 0xc000e57080)
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/dag/walk.go:381 +0x288
[2021-06-18T16:35:47.500Z]        created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update
[2021-06-18T16:35:47.500Z]        	/home/circleci/project/project/internal/dag/walk.go:304 +0x1246
[2021-06-18T16:35:47.500Z]        .
[2021-06-18T16:35:47.500Z]        
[2021-06-18T16:35:47.500Z]        Error: Error in function call
[2021-06-18T16:35:47.500Z]        

Crash Output

Expected Behavior

It execute successfully like 0.14.11 does.

Actual Behavior

Steps to Reproduce

Additional Context

References

@tbugfinder tbugfinder added bug new new issue not yet triaged labels Jun 18, 2021
@alisdair
Copy link
Member

Thanks for reporting this. Based on the stack trace and the error, I'm having trouble finding a reproduction case. Here's what I've tried:

locals {
  natgw_keys         = sensitive(toset(["a", "b", "c"]))
  onprem_cidr_blocks = toset([sensitive("z")])
}

output "product" {
  value = nonsensitive(setproduct(local.natgw_keys, local.onprem_cidr_blocks))
}

This validates and plans successfully. Can you adjust this to be more similar to your config in order to reproduce the panic?

@alisdair alisdair added crash functions v1.0 Issues (primarily bugs) reported against v1.0 releases waiting for reproduction unable to reproduce issue without further information waiting-response An issue/pull request is waiting for a response from the community and removed new new issue not yet triaged labels Jun 18, 2021
@tbugfinder
Copy link
Author

This is a code to replay.

locals {
  availability_zones_short = toset([substr(data.aws_availability_zones.available.names[0], -2, -1), substr(data.aws_availability_zones.available.names[1], -2, -1)])
  natgw_keys               = toset([for k in local.availability_zones_short : "natgw-${k}"])
  onprem_cidr_blocks = toset(["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16" ])
}

data "aws_availability_zones" "available" {
  state = "available"
}

output "setproduct" {
  value = setproduct(local.natgw_keys, local.onprem_cidr_blocks)
}

@alisdair alisdair added confirmed a Terraform Core team member has reproduced this issue and removed waiting for reproduction unable to reproduce issue without further information waiting-response An issue/pull request is waiting for a response from the community labels Jun 21, 2021
@alisdair
Copy link
Member

Thanks! This crashes for me with terraform validate.

@alisdair
Copy link
Member

Thanks again for the report. I have a fix for this in the upstream cty library here: zclconf/go-cty#109

@alisdair alisdair added explained a Terraform Core team member has described the root cause of this issue in code upstream labels Jun 21, 2021
@alisdair
Copy link
Member

Will be fixed in the upcoming 1.0.1 release.

@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 Jul 22, 2021
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 crash explained a Terraform Core team member has described the root cause of this issue in code functions upstream v1.0 Issues (primarily bugs) reported against v1.0 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants