v0.11.2
This is not a new issue but to draw attention that an existing issue has not been fixed (or have re-surfaced). Work-around with -var-file to specifiy .tfvars file works (with terraform plan/validate). Please close this ticket and re-open one of this existing ticket(s):
Ref.
https://github.com/hashicorp/terraform/issues/2659
https://github.com/hashicorp/terraform/issues/15894
Hi @AnthonyWC,
Can you explain which issue exactly you're referring to? The original cases in each of those linked issues are confirmed to work, but there are a number of confusing comments from users on both.
Since those specific cases are closed, we can use this issue to work on another use case.
Can you provide a configuration that demonstrates an issue?
Filenames with .tfvars in the same directory are not automatically being read when executing command such as terraform plan, you need to explicitly specific "-var-file=example1.tfvars".
aws.tf
provider "aws" {
version = ">= 0.11.2"
region = "us-east-1"
}
backend.tf
terraform {
backend "s3" {
bucket = foo
key = bar
region = "us-east-1"
}
}
data "terraform_remote_state" "dev-state" {
backend = "s3"
config {
bucket = "${var.s3-backend-bucket}"
key = "${var.s3-backend-key}"
}
}
vars-account.tf
variable "s3-backend-bucket" {}
variable "s3-backend-key" {}
vars.tfvars
s3-backend-bucket = "foo"
s3-backend-key = "bar"
Result:
#terraform plan
var.s3-backend-bucket
Enter a value:
#terraform plan -var-file="vars.tfvars"
Refreshing Terraform state in-memory prior to plan...
Hi @AnthonyWC,
That is the expected behavior, since many configurations rely on specifying different variable files from in the CLI flags. In the Variable Files documentation, the file names that are automatically loaded are terraform.tfvars or *.auto.tfvars.
Thanks, I thought it was supposed to load all .tfvars file in the directory. I am probably not the only one who was expecting that due to the way how it handles .tf file. :)
In documentation it says : "For all files which match terraform.tfvars or *.auto.tfvars present in the current directory, Terraform automatically loads them to populate variables." Not all *.tfvars files.
https://www.terraform.io/intro/getting-started/variables.html
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
Hi @AnthonyWC,
That is the expected behavior, since many configurations rely on specifying different variable files from in the CLI flags. In the Variable Files documentation, the file names that are automatically loaded are
terraform.tfvarsor*.auto.tfvars.