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]"
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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With