Reputation: 501
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]"
Upvotes: 8
Views: 7710
Reputation: 91
I've had the same problem: the only way I could get it to work was using the 'tfvars' file (as per the answer above) - but I found that syntax didn't work for me.
main.tf ...
variable people {
type = list
description = "List of names"
default = ["Blank1","Blank2","Blank3"]
}
output chosenname {
value = "The second element is ${(var.people[1])}"
}
and tfvars of ...
people=["Brown","Smith","Jones"]
then running with a vanilla >terraform plan gave me + chosenname = "The second element is Smith"
Upvotes: 0
Reputation: 10744
If anyone came here trying to figure out why this doesn't work with terragrunt; you need to escape the quotes:
terragrunt apply -var 'listvar=[\"abc1\", \"abc2\", \"abc3\"]'
Upvotes: 1
Reputation: 4777
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
Upvotes: 12