Interview Prep/Terraform/Variables, Locals, Outputs and Types

How do you pass a complex value through an environment variable?

IntermediateConceptVariables, Locals, Outputs and Types
Answer

TF_VAR_name takes HCL or JSON syntax for lists, maps and objects.

export TF_VAR_subnets='["10.0.1.0/24","10.0.2.0/24"]'
export TF_VAR_tags='{"team":"platform","env":"prod"}'

Handy in CI, though for large structures a .tfvars.json file is easier to review.

All Terraform questions Roadmap: Terraform

More on Variables, Locals, Outputs and Types