Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform: Providing list input values from command line?

Tags:

terraform

Is there a way to provide list values from the command line? There is variable merging for maps, but it doesn't seem to be working for lists. I was hoping for something like, but no luck... Thanks

terraform apply -var "listvar=abc1" -var "listvar=abc2"

or possibly

terraform apply -var "listvar=[abc1, abc2]"
like image 1000
user1198049 Avatar asked Aug 01 '17 13:08

user1198049


People also ask

How do you pass multiple values in Terraform?

There are two methods supported for doing this using the Terraform CLI when running Terraform commands. -var flag enables a single input variable value to be passed in at the command-line. -var-file flag enables multiple input variable values to be passed in by referencing a file that contains the values.

How do you input variables in Terraform?

Terraform variables allow you to write configuration that is flexible and easier to re-use. Add a variable to define the instance name. Create a new file called variables.tf with a block defining a new instance_name variable. Note: Terraform loads all files in the current directory ending in .

How do I run a command in Terraform?

The usual way to run Terraform is to first switch to the directory containing the . tf files for your root module (for example, using the cd command), so that Terraform will find those files automatically without any extra arguments.

How do I use environmental variables in Terraform?

Additionally, input variable values can also be set using Terraform environment variables. To do so, simply set the environment variable in the format TF_VAR_<variable name> . The variable name part of the format is the same as the variables declared in the variables.tf file.


Video Answer


1 Answers

I was able to get this to work as follow:

1) Your variable file should reflect as follow:

 variable "listvar" {
      description = "some varaible to list"
      type = "list"
    }

2) Then run the apply command as exactly as follow:

terraform apply -var 'listvar=["abc1", "abc2", "abc3"]'

I hope that helps

https://www.terraform.io/intro/getting-started/variables.html

like image 96
Innocent Anigbo Avatar answered Nov 13 '22 00:11

Innocent Anigbo