Preview local variable content

Is there a way to preview a local variable? I’d like to see the contents of the variable before applying a change.

Use case: I’m using HCL to define an AWS ECS task definition, including dynamic elements with for expressions. The HCL is passed through jsonencode(), zipped by archive_file and uploaded to S3 (for use with AWS CodeDeploy).

When running terraform plan, I only see that the etag/checksum has changed and the S3 object needs updating. I cannot find a way to preview the contents of neither the HCL nor the jsonencode() output.

Hi @sveniu!

If you run terraform console then you can try evaluating various expressions against the current state to see what results you get. If you type local.foo at the console prompt it should print out the value.

One caveat with this is that terraform console is not able to show a value that is derived from anything that Terraform only learns when creating a plan or applying a plan. As long as your local value is derived only from values that are defined statically in the configuration or exported by resources that already exist then it should work, but it will not work if the value is derived from resource instances that have not yet been created or from input variables (since input variables are set on a per-run basis during planning, and are not persistent between runs).

1 Like