terraform 0.7.8
tfvars variables
I am trying to create a netwok and subnet for a tenant in openstack and while doing that I created a map variable for the cidr attribute. The idea was to load this variable from a tfvars file so using the following config terraform actually says that there is an error
myvar = '{ key = "x.x.x.x" }'
invalid value "terraform.tfvars" for flag -var-file: Error parsing terraform.tfvars: At 1:25: illegal char
terraform validate doesn't complain at all about this tfvars but it complains at terraform plan
According to https://www.terraform.io/intro/getting-started/variables.html on __Assigning Maps__ we should be able to use this within the tfvars
$ terraform plan -var 'amis={ us-east-1 = "foo", us-west-2 = "bar" }'
Maybe I am wrong asumming that this can be set up on the tfvars? I moved this configs into the variables.tf and it works properly
There is another case where the tfvars syntax is the following
myvar = {key = "x.x.x.x"}
In this case terraform validate doesn't complain and terraform plan either but when terraform plan it complains
invalid value "terraform.tfvars" for flag -var-file: Error parsing terraform.tfvars: At 1:34: illegal char
With myvar = {key = "x.x.x.x"} everything works for me.
Your first example doesn't work because HCL doesn't allow single quote strings, and what you actually want is the native map anyways (what you did later on, and what worked for me above).
You almost had it! The syntax you do on the command line is the same but I think you assumed the value would be a string when in fact you can just copy and paste it directly and it would work!
Oh right, gotcha. Assumed that this needed to be quoted somehow at the tfvars file. thanks @mitchellh
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
With
myvar = {key = "x.x.x.x"}everything works for me.Your first example doesn't work because HCL doesn't allow single quote strings, and what you actually want is the native map anyways (what you did later on, and what worked for me above).
You almost had it! The syntax you do on the command line is the same but I think you assumed the value would be a string when in fact you can just copy and paste it directly and it would work!