I have a go process that invokes Terraform using go exec, to process more than one Terraform project. Think of terragrunt
. Let’s call it “runner”. Runner gets an initial set of input, and passes the same input to each project it processes. Some of the input might not be relevant to a particular project.
When passing in the input via terraform.tfvars.json
for a particular project, it works great, but unwanted warnings are generated for input that goes unused.
To avoid that I am trying to pass in the input using TF_VAR_
environment variables instead.
When it comes to passing in a structure, I am getting errors in Terraform that it is unable to find keys in the map.
For example, the Runner invokes go exec
with an environment variable such as
cmd.Env = append(cmd.Env, "TF_VAR_geo={region=\"us-central1\",zone=\"us-central1-c\",multizone=\"false\",location=\"us-central1-c\"}")
I put "bash", "-c", "echo $TF_VAR_geo"
in place of the terraform
executable and it prints
{zone="us-central1-c",multizone="false",location="us-central1-c",region="us-central1"}
But Terraform produces this:
│
│ Error: Unsupported attribute
│
│ on providers.tf line 12, in provider "google":
│ 12: region = var.geo.region
│ ├────────────────
│ │ var.geo is "{zone=\"us-central1-c\",multizone=\"false\",location=\"us-central1-c\",region=\"us-central1\"}"
│
│ Can't access attributes on a primitive-typed value (string).
╵
Why is terraform
treating the value as a string instead of a map?