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

Cannot parse value for variable for CIDR format #7971

Closed
tmtk75 opened this issue Aug 4, 2016 · 5 comments
Closed

Cannot parse value for variable for CIDR format #7971

tmtk75 opened this issue Aug 4, 2016 · 5 comments

Comments

@tmtk75
Copy link
Contributor

tmtk75 commented Aug 4, 2016

After upgrading to v0.7.0, I can see next error.

$ terraform -v
Terraform v0.7.0
...
$ terraform plan -var cidr=127.0.0.1/32
invalid value "cidr=127.0.0.1/32" for flag -var: Cannot parse value for variable cidr ("cidr=127.0.0.1/32") as valid HCL: At 1:11: expected: IDENT | STRING | ASSIGN | LBRACE got: FLOAT
Usage: terraform plan [options] [dir]

  Generates an execution plan for Terraform.

  This execution plan can be reviewed prior to running apply to get a
  sense for what Terraform will do. Optionally, the plan can be saved to
  a Terraform plan file, and apply can take this plan file to execute
  this plan exactly.

Options:

  -destroy            If set, a plan will be generated to destroy all resources
...

I could not see the error with v0.6.16.

$ /usr/local/bin/terraform -v
Terraform v0.6.16

Your version of Terraform is out of date! The latest version
is 0.7.0. You can update by downloading from www.terraform.io
...
$ /usr/local/bin/terraform plan -var cidr=127.0.0.1/32
Refreshing Terraform state prior to plan...

No changes. Infrastructure is up-to-date. This means that Terraform
could not detect any differences between your configuration and
the real physical resources that exist. As a result, Terraform
doesn't need to do anything.

Affected Resource(s)

variable, so it may be a terraform's core issue.

Terraform Configuration Files

I can reproduce with this one.

variable cidr {}

Expected Behavior

It works as 0.6.16.

Actual Behavior

I got next error.

invalid value "cidr=127.0.0.1/32" for flag -var: Cannot parse value for variable cidr ("cidr=127.0.0.1/32") as valid HCL: At 1:11: expected: IDENT | STRING | ASSIGN | LBRACE got: FLOAT
@apparentlymart
Copy link
Contributor

Hi @tmtk75. Sorry for the problem here.

It looks like in Terraform 0.7 the expected syntax here was changed to support passing maps and lists as variables, in addition to strings.

I'm not 100% sure (I didn't hit this issue myself yet, since I tend to use environment variables to set Terraform variables) but I think you could get around this by making the -var argument a valid HCL declaration, like this:

terraform plan -var 'cidr="127.0.0.1/32"'

An alternative, that might be easier to read and less confusing, would be to create a separate variables file using HCL syntax and then use -var-file to reference it.

@tmtk75
Copy link
Contributor Author

tmtk75 commented Aug 4, 2016

Hi @apparentlymart, thanks a lot to let me know the workaround!
It's pretty helpful to me!

Regarding my use-case, I'd like to dynamically give my current IP address into cidr_blocks of aws_security_group for a tentative instance.

I could fix my code like this and saw it worked as expected. Thank you so much!

terraform plan -var 'cidr="'`curl -s echoip.net`/32'"'
variable cidr {}

resource "aws_security_group" "test" {
...
  ingress {
      cidr_blocks = [ "${var.cidr}" ]

@kwilczynski
Copy link
Contributor

@tmtk75 you gave me an idea for interesting data source :)

ljfranklin added a commit to ljfranklin/terraform-resource that referenced this issue Aug 5, 2016
- Newest version of terraform changes how vars are parsed:
  hashicorp/terraform#7971
everpeace added a commit to everpeace/concourse-aws that referenced this issue Sep 6, 2016
@mitchellh
Copy link
Contributor

Closing since we got this figured out.

@ghost
Copy link

ghost commented Apr 19, 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 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants