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

file.tfvars not being read #17163

Closed
AnthonyWC opened this issue Jan 22, 2018 · 6 comments
Closed

file.tfvars not being read #17163

AnthonyWC opened this issue Jan 22, 2018 · 6 comments
Labels
bug config waiting-response An issue/pull request is waiting for a response from the community

Comments

@AnthonyWC
Copy link

Terraform Version

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.
#2659
#15894

@jbardin
Copy link
Member

jbardin commented Jan 30, 2018

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?

@jbardin jbardin added the waiting-response An issue/pull request is waiting for a response from the community label Jan 30, 2018
@AnthonyWC
Copy link
Author

AnthonyWC commented Jan 30, 2018

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...

@jbardin
Copy link
Member

jbardin commented Jan 30, 2018

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.

@jbardin jbardin closed this as completed Jan 30, 2018
@AnthonyWC
Copy link
Author

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. :)

@ltupin
Copy link

ltupin commented May 24, 2018

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

@ghost
Copy link

ghost commented Apr 3, 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 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

No branches or pull requests

3 participants