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

variables referenced without var. fail silently #8010

Closed
MarkHerhold opened this issue Aug 5, 2016 · 3 comments
Closed

variables referenced without var. fail silently #8010

MarkHerhold opened this issue Aug 5, 2016 · 3 comments

Comments

@MarkHerhold
Copy link

As a new user, I didn't realize I had to use var. to reference a variable as in "${var.my-service-name}". This caused a lot of issues for me such as security group rules not being created, tags not being created, etc.

Terraform Version

Terraform v0.7.0
(I also had this issue in 0.6.14)

Affected Resource(s)

Potentially everything that you can reference a variable in.
Specifically, I experienced issues using improperly referenced variables in aws_subnet, aws_security_group.

Expected Behavior

I would expect terraform plan to throw an error and terraform apply to completely fail during execution.

There should be an error stating "Cannot reference my-sg-name in main.tf at 55:10"

Actual Behavior

Everything shows up as computed and tags and other fields simply are not created.

Part of mail.tf:

resource "aws_security_group" "servers" {
  name        = "servers_sg"
  vpc_id      = "${aws_vpc.vpc.id}"
...
  tags {
    "Name" = "${my-sg-name}"
  }

Output:

~ aws_subnet.servers
    tags.%: "" => "<computed>"

References

See @Zapadlo 's comment in GH-6265 about variables failing silently

@mitchellh
Copy link
Contributor

Talked this over with @phinze and I'm going to tag this with "0.8":

We'd like to break some backwards compatibility to fix this the right way. The "right way" we believe is to make it so that template_file source parameter must be escaped if its a raw literal. The core ignores unprefixed variables (known internally as "simple" variables) only for this case and we think that wasn't the right decision.

However, this is a BC-incompat change so we will hold it until 0.8.

@mitchellh
Copy link
Contributor

The fix for this is in #9698 and HCL. This will be part of 0.8. Closing this as a dup though of #5338 realized it was there as well.

@ghost
Copy link

ghost commented Apr 20, 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 20, 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

3 participants