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

v1.10.0 panic with templatefile on terraform validate #36147

Closed
akettmann-id opened this issue Dec 2, 2024 · 2 comments
Closed

v1.10.0 panic with templatefile on terraform validate #36147

akettmann-id opened this issue Dec 2, 2024 · 2 comments
Labels
bug duplicate issue closed because another issue already tracks this problem

Comments

@akettmann-id
Copy link

akettmann-id commented Dec 2, 2024

Terraform Version

$ terraform version
Terraform v1.10.0
on linux_amd64
+ provider registry.terraform.io/hashicorp/archive v2.6.0

Terraform Configuration Files

# Generates a ZIP file from a local JavaScript file
data "archive_file" "lambda_zip" {
  type = "zip"
  source {
    content  = templatefile("${path.module}/scripts/auth_handler.py", var.basic_auth_creds)
    filename = "auth_handler.py"
  }
  output_path = "${path.module}/lambda_function.zip"
}
variable "basic_auth_creds" {
  type = object({
    username = string
    password = string
  })
  default = {
    username = "secretname"
    password = "idproject"
  }
}

Debug Output

Note, this is running terraform validate not terraform plan or apply.

https://gist.github.com/akettmann-id/73c5aa6a0a144eaa06fdf8352b090822

Expected Behavior

Validation completes successfully.

Actual Behavior

Panic error

$ terraform validate
╷
│ Error: Error in function call
│ 
│   on modules/https_lb/password_protection_lambda.tf line 5, in data "archive_file" "lambda_zip":
│    5:     content  = templatefile("${path.module}/scripts/auth_handler.py", var.basic_auth_creds)
│     ├────────────────
│     │ while calling templatefile(path, vars)
│     │ path.module is "modules/https_lb"
│     │ var.basic_auth_creds is a object
│ 
│ Call to function "templatefile" failed: panic in function implementation: can't use ElementIterator on unknown value
│ goroutine 266 [running]:
│ runtime/debug.Stack()
│       runtime/debug/stack.go:26 +0x5e
│ github.com/zclconf/go-cty/cty/function.errorForPanic(...)
│       github.com/zclconf/[email protected]/cty/function/error.go:44
│ github.com/zclconf/go-cty/cty/function.Function.Call.func2()
│       github.com/zclconf/[email protected]/cty/function/function.go:349 +0x9b
│ panic({0x3050be0?, 0x3ddadb0?})
│       runtime/panic.go:785 +0x132
│ github.com/zclconf/go-cty/cty.Value.ElementIterator({{{0x3e20e90?, 0xc000a2dba0?}}, {0x315d760?, 0x5a112e0?}})
│       github.com/zclconf/[email protected]/cty/value_ops.go:1193 +0xd1
│ github.com/zclconf/go-cty/cty.Value.AsValueMap({{{0x3e20e90?, 0xc000a2dba0?}}, {0x315d760?, 0x5a112e0?}})
│       github.com/zclconf/[email protected]/cty/value_ops.go:1455 +0x99
│ github.com/hashicorp/terraform/internal/lang/funcs.MakeTemplateFileFunc.makeRenderTemplateFunc.func4({0x3e21108, 0xc00089b9e0}, {{{0x3e20e90?,
│ 0xc000a2dba0?}}, {0x315d760?, 0x5a112e0?}})
│       github.com/hashicorp/terraform/internal/lang/funcs/string.go:322 +0xea
│ github.com/hashicorp/terraform/internal/lang/funcs.MakeTemplateFileFunc.func3({0xc004625f00?, 0xc000a2dba0?, 0x315d760?}, {{0x3e21598?,
│ 0x5a43160?}})
│       github.com/hashicorp/terraform/internal/lang/funcs/filesystem.go:148 +0x245
│ github.com/zclconf/go-cty/cty/function.Function.Call({0x3e20e90?}, {0xc004625f00, 0x2, 0x2})
│       github.com/zclconf/[email protected]/cty/function/function.go:353 +0x6bf
│ github.com/hashicorp/hcl/v2/hclsyntax.(*FunctionCallExpr).Value(0xc00039f3b0, 0xc004107b90)
│       github.com/hashicorp/hcl/[email protected]/hclsyntax/expression.go:528 +0x1acf
│ github.com/hashicorp/hcl/v2/hcldec.(*AttrSpec).decode(0xc000add0b0, 0xc000add080?, {0xc0056f48f8?, 0x60?, 0x28?}, 0xc004107b90)
│       github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:220 +0x1fc
│ github.com/hashicorp/hcl/v2/hcldec.ObjectSpec.decode(0xc000add080, 0xc0029ae600, {0x5a43160, 0x0, 0x0}, 0xc004107b90)
│       github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:94 +0x1f8
│ github.com/hashicorp/hcl/v2/hcldec.decode({0x3e22ad0, 0xc004122a40}, {0x5a43160, 0x0, 0x0}, 0xc004107b90, {0x3e21618, 0xc000add080}, 0x0)
│       github.com/hashicorp/hcl/[email protected]/hcldec/decode.go:24 +0x10f
│ github.com/hashicorp/hcl/v2/hcldec.(*BlockSetSpec).decode(0xc0031f31d0, 0xc0029ae4e0, {0xc000deb9e0?, 0xd?, 0x28?}, 0xc004107b90)
│       github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:767 +0x1ff
│ github.com/hashicorp/hcl/v2/hcldec.ObjectSpec.decode(0xc0031f2e40, 0xc0029ae4e0, {0x0, 0x0, 0x0}, 0xc004107b90)
│       github.com/hashicorp/hcl/[email protected]/hcldec/spec.go:94 +0x1f8
│ github.com/hashicorp/hcl/v2/hcldec.decode({0x3e22ad0, 0xc0041229e0}, {0x0, 0x0, 0x0}, 0xc004107b90, {0x3e21618, 0xc0031f2e40}, 0x0)
│       github.com/hashicorp/hcl/[email protected]/hcldec/decode.go:24 +0x10f
│ github.com/hashicorp/hcl/v2/hcldec.Decode(...)
│       github.com/hashicorp/hcl/[email protected]/hcldec/public.go:18
│ github.com/hashicorp/terraform/internal/lang.(*Scope).EvalBlock(0xc000b82090, {0x3e21060, 0xc004a1f720}, 0xc000adc8a0)
│       github.com/hashicorp/terraform/internal/lang/eval.go:75 +0x207
│ github.com/hashicorp/terraform/internal/terraform.(*BuiltinEvalContext).EvaluateBlock(0xc000c67f20?, {0x3e21390, 0xc000a3cb00}, 0xc000adc8a0,
│ {0x0?, 0x0?}, {{{{0x0, 0x0}}, {0x0, 0x0}}, ...})
│       github.com/hashicorp/terraform/internal/terraform/eval_context_builtin.go:324 +0x145
│ github.com/hashicorp/terraform/internal/terraform.(*NodeValidatableResource).validateResource(0xc000f1e250, {0x3e48bb8, 0xc0048b4200})
│       github.com/hashicorp/terraform/internal/terraform/node_resource_validate.go:425 +0xf06
│ github.com/hashicorp/terraform/internal/terraform.(*NodeValidatableResource).Execute(0xc000f1e250, {0x3e48bb8, 0xc0048b4200}, 0x50?)
│       github.com/hashicorp/terraform/internal/terraform/node_resource_validate.go:56 +0xb8
│ github.com/hashicorp/terraform/internal/terraform.(*ContextGraphWalker).Execute(0xc00090a420, {0x3e48bb8, 0xc0048b4200}, {0x7b50827ae090,
│ 0xc000f1e250})
│       github.com/hashicorp/terraform/internal/terraform/graph_walk_context.go:161 +0xb5
│ github.com/hashicorp/terraform/internal/terraform.(*Graph).walk.func1({0x36b4c40, 0xc000f1e250})
│       github.com/hashicorp/terraform/internal/terraform/graph.go:143 +0x7c3
│ github.com/hashicorp/terraform/internal/dag.(*Walker).walkVertex(0xc0007a8f60, {0x36b4c40, 0xc000f1e250}, 0xc0005e1ac0)
│       github.com/hashicorp/terraform/internal/dag/walk.go:384 +0x2d1
│ created by github.com/hashicorp/terraform/internal/dag.(*Walker).Update in goroutine 1
│       github.com/hashicorp/terraform/internal/dag/walk.go:307 +0xfb3
│ .
╵

Steps to Reproduce

  1. create main.tf in empty directory
  2. create scripts directory
  3. create file named auth_handler.py inside of the scripts directory, content unnecessary
  4. terraform validate

Additional Context

Validates properly on terraform 1.9.8-1 or:

Terraform v1.9.8
on linux_amd64
+ provider registry.terraform.io/hashicorp/archive v2.6.0

Your version of Terraform is out of date! The latest version
is 1.10.0. You can update by downloading from https://www.terraform.io/downloads.html

References

No response

@akettmann-id akettmann-id added bug new new issue not yet triaged labels Dec 2, 2024
@jbardin
Copy link
Member

jbardin commented Dec 2, 2024

Duplicate of #36110

@jbardin jbardin marked this as a duplicate of #36110 Dec 2, 2024
@jbardin jbardin closed this as completed Dec 2, 2024
@crw crw added duplicate issue closed because another issue already tracks this problem and removed new new issue not yet triaged labels Dec 2, 2024
Copy link
Contributor

github-actions bot commented Jan 2, 2025

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 Jan 2, 2025
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