-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Unknown values when decoding empty but yaml documents #31188
Copy link
Copy link
Closed
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in codefunctionsupstream
Description
Terraform Version
Terraform v1.1.9
on darwin_arm64
Terraform code
output "test" {
value = {
empty = try(yamldecode(file("./empty.yml")), {})
started = yamldecode(file("./started.yml"))
val = yamldecode(file("./val.yml"))
}
}Debug Output
$ terraform plan
+ test = {
+ empty = {}
+ started = (known after apply)
+ val = {
+ a = "b"
+ c = 1
}
}
$ terraform apply -auto-approve
Changes to Outputs:
+ test = {
+ empty = {}
+ started = (known after apply)
+ val = {
+ a = "b"
+ c = 1
}
}
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
test = {
"empty" = {}
"started" = null
"val" = {
"a" = "b"
"c" = 1
}
}
$ terraform apply -auto-approve
Changes to Outputs:
~ test = {
~ started = null -> (known after apply)
# (2 unchanged elements hidden)
}
You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
test = {
"empty" = {}
"started" = null
"val" = {
"a" = "b"
"c" = 1
}
}
Expected Behavior
started should have value null at plan time.
I'm not sure that this behavior is defined in the docs - but its important because the apply promise of 'unknown' is a contagious property, and will force values to be reloaded and re-evaluated each terraform apply.
Actual Behavior
started has an unknown value at plan.
Steps to Reproduce
#!/bin/bash
touch empty.yml
cat << EOF > started.yml
---
EOF
cat << EOF > val.yml
a: b
c: 1
EOF
cat << EOF > main.tf
output "test" {
value = {
empty = try(yamldecode(file("./empty.yml")), {})
started = yamldecode(file("./started.yml"))
val = yamldecode(file("./val.yml"))
}
}
EOF
terraform init
terraform planAdditional Context
no additional context
References
Unrelated but indicative reading: https://log.martinatkins.me/2021/06/14/terraform-plan-unknown-values/
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugconfirmeda Terraform Core team member has reproduced this issuea Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in codefunctionsupstream