hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.72k stars 9.55k forks source link

setproduct panics on empty lists #28605

Closed tzepf closed 3 years ago

tzepf commented 3 years ago

Terraform Version

Terraform v0.15.1
on darwin_amd64

Terraform Configuration Files

locals {
    set-a = []
    set-b = []
    set-a-b = setproduct(local.set-a, local.set-b)
}

output "set-a-b" {
    value = local.set-a-b
}

Debug Output

Crash Output

Expected Behavior

$ terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:

Terraform will perform the following actions:

Plan: 0 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + set-a-b = []

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

set-a-b = tolist([])

Actual Behavior

$ terraform apply
╷
│ Error: Error in function call
│ 
│   on empty-setproduct.tf line 4, in locals:
│    4:     set-a-b = setproduct(local.set-a, local.set-b)
│     ├────────────────
│     │ local.set-a is empty tuple
│     │ local.set-b is empty tuple
│ 
│ Call to function "setproduct" failed: panic in function implementation: runtime error: hash of unhashable type cty.ValueMarks
│ goroutine 82 [running]:
│ runtime/debug.Stack(0xc000137fd8, 0x3018fc0, 0xc0002e1820)
│   /usr/local/go/src/runtime/debug/stack.go:24 +0x9f
│ github.com/zclconf/go-cty/cty/function.errorForPanic(...)
│   /go/pkg/mod/github.com/zclconf/go-cty@v1.8.2/cty/function/error.go:44
│ github.com/zclconf/go-cty/cty/function.Function.Call.func1(0xc000138790, 0xc0001387b0)
│   /go/pkg/mod/github.com/zclconf/go-cty@v1.8.2/cty/function/function.go:291 +0x93
│ panic(0x3018fc0, 0xc0002e1820)
│   /usr/local/go/src/runtime/panic.go:965 +0x1b9
│ github.com/zclconf/go-cty/cty.Value.Mark(0x3835d18, 0xc0002e17d0, 0x2edef60, 0xc0006b4768, 0x30c5400, 0x0, 0x3398160,
│ 0xc0006a5ad0, 0x0, 0xc0006b4750)
│   /go/pkg/mod/github.com/zclconf/go-cty@v1.8.2/cty/marks.go:208 +0x1dc
│ github.com/zclconf/go-cty/cty/function/stdlib.glob..func33(0xc0006c4180, 0x2, 0x2, 0x3835d18, 0xc0002e1780, 0xc0002e1780,
│ 0x0, 0x0, 0x48f2100, 0x100d801, ...)
│   /go/pkg/mod/github.com/zclconf/go-cty@v1.8.2/cty/function/stdlib/collection.go:956 +0xf05
│ github.com/zclconf/go-cty/cty/function.Function.Call(0xc00018fce0, 0xc0006c4180, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
│   /go/pkg/mod/github.com/zclconf/go-cty@v1.8.2/cty/function/function.go:295 +0x4a7
│ github.com/hashicorp/hcl/v2/hclsyntax.(*FunctionCallExpr).Value(0xc000642000, 0xc0006b4738, 0x0, 0xc000139800, 0x1, 0x1, 0x0,
│ 0x0, 0x0)
│   /go/pkg/mod/github.com/hashicorp/hcl/v2@v2.9.1/hclsyntax/expression.go:442 +0xff6
│ github.com/hashicorp/terraform/lang.(*Scope).EvalExpr(0xc0006ba140, 0x3834b28, 0xc000642000, 0x3835ce0, 0x48f2100, 0x0, 0x0,
│ 0x0, 0x0, 0x0, ...)
│   /home/circleci/project/project/lang/eval.go:171 +0x1bc
│ github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).EvaluateExpr(0xc00065d380, 0x3834b28, 0xc000642000, 0x3835ce0,
│ 0x48f2100, 0x0, 0x0, 0x0, 0xffffffffffffffff, 0x0, ...)
│   /home/circleci/project/project/terraform/eval_context_builtin.go:280 +0xbb
│ github.com/hashicorp/terraform/terraform.(*NodeLocal).Execute(0xc0006a4b70, 0x386ba90, 0xc00065d380, 0xc000180004,
│ 0xc000032ce8, 0x100b805, 0x3042560)
│   /home/circleci/project/project/terraform/node_local.go:153 +0x67d
│ github.com/hashicorp/terraform/terraform.(*ContextGraphWalker).Execute(0xc000658480, 0x386ba90, 0xc00065d380, 0x575f018,
│ 0xc0006a4b70, 0x0, 0x0, 0x0)
│   /home/circleci/project/project/terraform/graph_walk_context.go:127 +0xbf
│ github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x31c4440, 0xc0006a4b70, 0x0, 0x0, 0x0)
│   /home/circleci/project/project/terraform/graph.go:59 +0xbd3
│ github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc0006a60c0, 0x31c4440, 0xc0006a4b70, 0xc0006c4040)
│   /home/circleci/project/project/dag/walk.go:381 +0x288
│ created by github.com/hashicorp/terraform/dag.(*Walker).Update
│   /home/circleci/project/project/dag/walk.go:304 +0x1246
│ .

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

References

alisdair commented 3 years ago

Hi @tzepf, thanks for reporting this! Closing as duplicate of #28524.

github-actions[bot] commented 3 years ago

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.