Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing value via -var fails #8044

Closed
hugoduncan opened this issue Aug 8, 2016 · 12 comments · Fixed by #8620
Closed

Passing value via -var fails #8044

hugoduncan opened this issue Aug 8, 2016 · 12 comments · Fixed by #8620
Assignees

Comments

@hugoduncan
Copy link
Contributor

hugoduncan commented Aug 8, 2016

The following command fails with any terraform .tf files.

$ terraform -d plan  -var "image=1234.dkr.ecr.us-east-1.amazonaws.com/proj:abcdef" 
invalid value "image='1234.dkr.ecr.us-east-1.amazonaws.com/proj:abcdef'" for flag -var: Cannot parse value for variable image ("image='1234.dkr.ecr.us-east-1.amazonaws.com/proj:abcdef'") as valid HCL: At 1:7: illegal char

I would have expected anything after the = to have been assigned to the var image.

$ terraform -v
Terraform v0.7.0
@qnu
Copy link

qnu commented Aug 8, 2016

Passing a map also fails:
terraform plan -var 'somemap={ env = "env", service = "zoo" }'
somemap["env"] is empty. terraform v0.7.0

Now using TF_VAR_somemap as the workaround.

@Nomon
Copy link

Nomon commented Aug 9, 2016

-var git_sha=9af86eacf7656af1279557d0ab887cc52622f37f in terraform apply causes:
invalid value "git_sha=9af86eacf7656af1279557d0ab887cc52622f37f" for flag -var: Cannot parse value for variable git_sha ("git_sha=9af86eacf7656af1279557d0ab887cc52622f37f") as valid HCL: key 'af86eacf7656af1279557d0ab887cc52622f37f' expected start of object ('{') or assignment ('=')

Not sure if intended but a fix is to pass the variables as:
-var 'git_sha="xyz"'

@thatarchguy
Copy link

I'm experiencing this as well.
The problem is when it starts with a number for me.

Adding a letter to the start or single quoting like @Nomon described works.

$ terraform plan -var "revision=23d324" deploy
invalid value "revision=23d324" for flag -var: Cannot parse value for variable revision ("revision=23d324") as valid HCL: key 'd324' expected start of object ('{') or assignment ('=')

# adding a letter the the beginning
$ terraform plan -var "revision=test-23d324" deploy
[works]

# using single quote
$ terraform plan -var 'revision="23d324"' deploy
[works]

$ terraform version
Terraform v0.7.0

@hugoduncan
Copy link
Contributor Author

Adding a letter doesn't seem to be a workaround, as terraform doesn't have any substring function, iiiuc.

I'm having trouble coming up with something that works when interpolating in value from the environment, e.g. for:

terraform plan -var revision="${revision}" deploy

I'm resorting to generating a script with the command that uses the single quotes, and then calling the script.

@hugoduncan
Copy link
Contributor Author

Possibly related, passing a number to a var requires single quoting too, otherwise an error results:

* variable host_port should be type string, got number

@Nomon
Copy link

Nomon commented Aug 11, 2016

@hugoduncan the single quotes are there to prevent shell from eating the double quotes. -var foo="${bar}" should do the same while allowing interpolation.

@thecodeassassin
Copy link

when i pass a location to a file as a var it fails as well:

terraform $OPERATION \
    state "${ENVIRONMENT}.tfstate" \
    -var "credentials='../credentials.json'" \

invalid value "credentials='../credentials.json'" for flag -var: Cannot parse value for variable credentials ("credentials='../../gce_credentials/staging/credentials.json'") as valid HCL: At 1:13: illegal char

This happens since i upgraded to 0.7.0

@thatarchguy
Copy link

Looks like it stems from
681d94a

The author explains that a special check was made for CLI supplied variables

In order to continue supporting the -var "foo=bar" type of variable
flag (which is not valid HCL), a special case error is checked after HCL
parsing fails, and the old code path runs instead.

Maybe a problem exists in the special check when the variable starts with a number? I'm not too familiar with Go.

@thecodeassassin
Copy link

thecodeassassin commented Aug 12, 2016

Looks like it stems from
681d94a

This is correct, what happens is that it tries to load the path i am supplying as a variable to the parseVarFlagAsHCL method which causes it to read it as a file. It shouldn't read it as a file at all since i just want to supply the path as a variable (to provide a path to the credentials file needed to authenticate against google cloud). @jen20 Can you confirm this?

I would say this is a critical bug because it makes 0.7.0 unusable for me.

@anosulchik
Copy link

We noticed this issue at terraform 0.7.2.

@plentz
Copy link

plentz commented Aug 31, 2016

@hugoduncan the issue you're talking about is #7962

@mitchellh mitchellh self-assigned this Sep 2, 2016
combor pushed a commit to alphagov/paas-docker-cloudfoundry-tools that referenced this issue Sep 6, 2016
combor pushed a commit to alphagov/paas-docker-cloudfoundry-tools that referenced this issue Sep 6, 2016
@ghost
Copy link

ghost commented Apr 22, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants