Terraform: Terraform is crashing when null is passed to compact function

Created on 10 Jul 2019  ยท  2Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.12.3

Terraform Configuration Files

locals {
  a = compact(["a", "", "b", "c", null])
}

output "a" {
value = local.a
}

Debug Output

Crash Output

Call to function "compact" failed: panic in function implementation: value is
null
goroutine 29 [running]:
runtime/debug.Stack(0xc000340208, 0x19dddc0, 0x2190d30)
/opt/goenv/versions/1.12.4/src/runtime/debug/stack.go:24 +0x9d
github.com/zclconf/go-cty/cty/function.errorForPanic(...)
/opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/[email protected]/cty/function/error.go:44
github.com/zclconf/go-cty/cty/function.Function.Call.func1(0xc000340568,
0xc000340588)
/opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/[email protected]/cty/function/function.go:239
+0x8f
panic(0x19dddc0, 0x2190d30)
/opt/goenv/versions/1.12.4/src/runtime/panic.go:522 +0x1b5
github.com/zclconf/go-cty/cty.Value.AsString(...)
/opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/[email protected]/cty/value_ops.go:1029
github.com/hashicorp/terraform/lang/funcs.glob..func12(0xc0004d5bc0, 0x1, 0x1,
0x2206c80, 0xc000362da0, 0xc000362da0, 0x0, 0x0, 0x76302f, 0x2206d80, ...)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/funcs/collection.go:249
+0x53d
github.com/zclconf/go-cty/cty/function.Function.Call(0xc000326ed0,
0xc0004d5bc0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/zclconf/[email protected]/cty/function/function.go:243
+0x2f8
github.com/hashicorp/hcl2/hcl/hclsyntax.(FunctionCallExpr).Value(0xc000548000,
0xc0004d5ba0, 0x0, 0xc000341700, 0x1, 0x1, 0x0, 0x0, 0x0)
/opt/teamcity-agent/work/9e329aa031982669/pkg/mod/github.com/hashicorp/[email protected]/hcl/hclsyntax/expression.go:385
+0x10c8
github.com/hashicorp/terraform/lang.(
Scope).EvalExpr(0xc0000b4b40, 0x2205900,
0xc000548000, 0x2206c40, 0x3311ca0, 0x0, 0x1ba37e0, 0x0, 0xc0004d4e60,
0xc0001458e0, ...)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/lang/eval.go:95
+0x1b3
github.com/hashicorp/terraform/terraform.(BuiltinEvalContext).EvaluateExpr(0xc00013d5f0,
0x2205900, 0xc000548000, 0x2206c40, 0x3311ca0, 0x0, 0x0, 0x0, 0xc00036f9f0,
0x434d6c, ...)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:284
+0x1e4
github.com/hashicorp/terraform/terraform.(
EvalLocal).Eval(0xc0004d4e00,
0x22388c0, 0xc00013d5f0, 0x2, 0x2, 0xf46ded, 0x1aeddc0)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval_local.go:43
+0x73a
github.com/hashicorp/terraform/terraform.EvalRaw(0x21c5580, 0xc0004d4e00,
0x22388c0, 0xc00013d5f0, 0x1a70ce0, 0x31c7105, 0x19dddc0, 0xc00012f5b0)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval.go:57
+0x131
github.com/hashicorp/terraform/terraform.Eval(0x21c5580, 0xc0004d4e00,
0x22388c0, 0xc00013d5f0, 0xc0004d4e00, 0x21c5580, 0xc0004d4e00, 0x0)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/eval.go:35
+0x4d
github.com/hashicorp/terraform/terraform.(Graph).walk.func1(0x1bfdd20,
0xc000466f60, 0x0, 0x0, 0x0)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/terraform/graph.go:90
+0xf40
github.com/hashicorp/terraform/dag.(
Walker).walkVertex(0xc000124280,
0x1bfdd20, 0xc000466f60, 0xc000260640)
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/dag/walk.go:392
+0x353
created by github.com/hashicorp/terraform/dag.(*Walker).Update
/opt/teamcity-agent/work/9e329aa031982669/src/github.com/hashicorp/terraform/dag/walk.go:314
+0xa9b
.

Expected Behavior

Output should be:

["a", "b", "c"]

Actual Behavior

Terraform crashed

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform apply

Additional Context

References

bug config crash

Most helpful comment

I'm not sure if this is intended or not; while looking at the code, I see that there is a mention that null values in functions (I guess, with the implicit exclusion of coalesce()) are supposed to panic.

Nonetheless, I've fixed the issue in the associated PR, so if the maintainers decide to allow null value, the PR is ready (at least for review).

All 2 comments

I'm not sure if this is intended or not; while looking at the code, I see that there is a mention that null values in functions (I guess, with the implicit exclusion of coalesce()) are supposed to panic.

Nonetheless, I've fixed the issue in the associated PR, so if the maintainers decide to allow null value, the PR is ready (at least for review).

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.

Was this page helpful?
0 / 5 - 0 ratings