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

terraform plan/apply with "-var-file=<custom_value>"still loads terraform.tfvars if present #25129

Open
lubo-p opened this issue Jun 4, 2020 · 1 comment

Comments

@lubo-p
Copy link

lubo-p commented Jun 4, 2020

Terraform Version

Terraform v0.12.25
+ provider.null v2.1.2

Terraform Configuration Files

main.tf:
resource null_resource test_resource {
  triggers = {
    val = var.test_val
  }
  provisioner "local-exec" {
    command = "echo ${var.test_val}"
  }
}

variables.tf:
variable test_val {
  type = string
}

custom.tfvars:
test_val1="custom"

terraform.tfvars:
test_val="default"

Debug Output

Crash Output

Expected Behavior

When running terraform plan or apply and providing custom value of -var-file and -state, the expectation is that only these specified files will be loaded.

Actual Behavior

According to my experiment if terraform.tfvars exists in the same directory and some value is missing in "custom" provided tfvar files, it will gets loaded from terrafrom.tfvars when such file should be not read at all.

Steps to Reproduce

$ terraform init
$ terraform plan -var-file=./custom.tfvars -state=./custom.tfstate
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

  • create

Terraform will perform the following actions:

null_resource.test_resource will be created

  • resource "null_resource" "test_resource" {
    • id = (known after apply)
    • triggers = {
      • "val" = "default"
        }
        }

Plan: 1 to add, 0 to change, 0 to destroy.

Now if I delete the terraform.tfvars I get the expected behavior - asking for missing value:
$ rm terraform.tfvars
$ terraform plan -var-file=./custom.tfvars -state=./custom.tfstate
var.test_val
Enter a value:

Additional Context

References

@apparentlymart
Copy link
Member

Hi @lubo-p,

Always loading the terraform.tfvars and *.auto.tfvars files is the intended behavior reflected in the documentation. -var and -var-file arguments are interpreted as overrides for those automatic files, if present.

There is not currently any way to tell Terraform via the command line not to process the automatic variables. The only way to stop them being processed is to rename them to not be recognized as automatically-included.

It seems this issue is implying a feature request for some way to tell Terraform to not automatically load these files, so I'm going to label it with that in mind. Please let me know if that wasn't what you intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants