Skip to content

Unknown values when decoding empty but yaml documents #31188

@lexton

Description

@lexton

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 plan

Additional Context

no additional context

References

Unrelated but indicative reading: https://log.martinatkins.me/2021/06/14/terraform-plan-unknown-values/

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugconfirmeda Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in codefunctionsupstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions