-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
terraform.tfvars not being read #2659
Comments
+1 This is a major regression from the previous versions. terraform.tfvars should be read by default as previously. |
Sorry for the confusing behavior, but this was actually a correction of a bug we'd been harboring for several previous versions. Variables need to be declared with a The |
I have variables.tf file with all variable declarations in the same directory as the main *.tf. And behavior for me as described. I though all *.tf files were being read at the same time and then final map is constructed out of those individual files. Or do we need to put: block in the main *.tf file? |
@alexintel oh interesting! Reopening and I'll try to reproduce and follow up with you. |
You're right @alexintel. I have been scratching my head about this for a while and it seems like the variables need to be read in first. What confused me was that terraform was applying fine locally but when I pushed, Atlas wouldn't be able to find these variables... anyway, I hope this helps. |
Hey folks, Having trouble reproducing this... here'e my test case, perhaps you can point out what I'm missing: // ==> main.tf <==
resource "aws_vpc" "foo" {
cidr_block = "${var.cidr}"
}
// ==> terraform.tfvars <==
cidr = "10.11.0.0/16"
// ==> variables.tf <==
variable "cidr" {} With the above (and AWS provider config via env vars), both |
Try the following: skip terraform.tfvars file completely, and in variables.tf try
Don't pass: -var-file=./terraform.tfvars on the command line. From what I understand from the documentation terraform.tfvars should be read automatically (and it is, in versions <=0.5.3). I only use terraform.tfvars for things like AWS keys so I can exclude it from git. |
@alexintel yep that works for me too... // ==> main.tf <==
resource "aws_vpc" "foo" {
cidr_block = "${var.cidr}"
}
// ==> variables.tf <==
variable "cidr" {
default = "10.11.0.0/16"
} Perhaps you're hitting #2613 - which was fixed in 0.6.1? |
There hasn't been a response on this in quite awhile and I haven't heard of this happening recently in new issues either. Going to close as fixed, perhaps it was just fixed in between at some point. All mentioned issues here are fixed as well. |
I am facing the same problem.. GitRepo: https://github.com/gfisaris/iac-terraform-aws-full_stack_template Could please anyone assist ? |
Same problem here.
And
Running
|
You have to define the variable:
In your configuration |
just to clarify what @mitchellh suggested above, because it works: in your
but you still need to define the variables in your configuration file, e.g.
|
Thanks to both @mitchellh and @michalmikolajczyk :-) |
Please tell me if this belongs somewhere else; I don't want to annoy or do the wrong thing here. I'm new to terraform and trying it out for the first time, modeling my layout on the best-practices repo somewhat. I'm using terraform v0.8.2 I have a terraform.tfvars file in a directory alongside my provider config. Something like: terraform/ in terraform/lab.tf I'm including "terraform/providers/vcloud/lab" as a module source. When I run terraform get in the top level directory, I get an error that one of my required variables is unset, even though that variable is defined in the terraform.tfvars file. That variable is defined in the nested lab.tf file; it's a provider-specific setting that seemed to make sense to keep with the nested module. To test to see if the terraform.tfvars file was being read, I added a default to the problem variable in the nested tf file in the module and re-ran. Now the error highlights another required variable being unset. So it really seems like the nested terraform.tfvars file isn't being read. Is this expected? |
This bug is not fixed (as of v0.11.2) and looks like it has been around for awhile; I think ticket should be re-open but I will open another one to reference this one. There are multiple ticket/reference of this issue in different manifestation, see: This workaround is to use -var-file to explicitly state tfvars file |
|
@anilybba: I am also, facing the same issue, did you find any work around for this ? |
I also have this issue.
It is as though tfvars are not working for me at all. |
Facing the same issue. In my Variables.tf, I have variable "aws_vpc_cidr_block" { In my prod.tfvars, I have In my root.tf I have module "vpc" { in my vpc/main.tf, I have resource "aws_vpc" "production" { cidr_block = "172.35.0.0/16"
} Now when I do plan, I get the below error ➜ Terraform git:(master) ✗ terraform plan -var-file=prod.tfvars Error: resource 'aws_vpc.production' config: unknown variable referenced: 'aws_vpc_cidr_block'; define it with a 'variable' block |
My friend and I both reproduced this issue after following https://www.hashicorp.com/resources/hangout-terraform-azure-for-beginners Is |
My friend and I both reproduced this issue after following https://www.hashicorp.com/resources/hangout-terraform-azure-for-beginners Is |
@v6 Make sure you do 'terraform init' |
Hi all, Whatever problem you are seeing now is something different than what this bug was about because the codepaths in question have changed considerably since 0.6.0. Please open new issues and complete the bug report template in full so we can understand what is going on and whether there is a new bug to fix. |
Was it ever fixed? |
If so, new issue. |
what about forcing it by passing in an argument when you run terraform, eg. terraform plan -var-flle="myvariable.tfvar" |
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. |
Just bumped to v0.6.0 and seeing the following error when attempting to use the
var-file=terrafrom.tfvars
command line flag.Here is the relevant content of the terraform.tfvars file:
Here is the full command I am running:
I can get this working by creating
variables
blocks in main tf file but was hoping to abstract those variables out so that they could be reused.The text was updated successfully, but these errors were encountered: