Home > Software engineering >  How to pass pass a list as env variables to be consumed by Terraform?
How to pass pass a list as env variables to be consumed by Terraform?

Time:10-26

I am working on a terraform project that has a variable as such:

variable "datalake_layers" {
  type = list
  default = ["raw", "bronze", "silver", "gold"]
}

Now I would like to pass the list through the environment (os variable). The way I've been passing other os variables is by running config.sh file before terraform commands are executed. Contents of the shell script look like this:

export TF_VAR_tfinfra_storage_akey="some_storage_key"
export TF_VAR_rg_name="some_resourcegroup_name"

How can I achieve a similar setup with a list instead of a string? Could I set env variable like this and convert this to Terraform list somehow? I couldn't find a way to do this. Or is there a better way?

export TF_VAR_datalake_layers="["raw", "bronze", "silver", "gold"]"

CodePudding user response:

Yes, but you have to use single quotes:

export TF_VAR_datalake_layers='["raw", "bronze", "silver", "gold"]'
  • Related