Skip to content

Terraform 0.12.0-alpha no longer allows assignments in terraform.tfvars without a corresponding variable declaration #19424

@lubars

Description

@lubars

Terraform Version

Terraform v0.12.0-alpha2
+ provider.google v1.19.1-4-gf3de5334
+ provider.null v1.0.0-5-gf54ff98

Expected Behavior

Terraform v0.11.10 and earlier allowed assignments to occur in terraform.tfvars without a corresponding variable declaration in infrastructure.tf.

Actual Behavior

This now results in errors such as the following:

Error: Value for undeclared variable

  on terraform.tfvars line 4:
   4: AMI = "ami-18726478"

The root module does not declare a variable named "AMI". To use this value,
add a "variable" block to the configuration.

Steps to Reproduce

  1. Add an entry to terraform.tfvars without a corresponding variable declaration in infrastructure.tf
  2. terraform plan

Additional Context

We generate a common terraform.tfvars file shared by multiple provider-specific infrastucture.tf files. Only a subset of the assignments in terraform.tfvars are referenced in a given infrastructure.tf file. Up until v0.11.10, assignments in terraform.tfvars without a corresponding variable declaration in a given infrastructure.tf were ignored. The previous behavior should be supported, or perhaps a flag (e.g. "-ignore-undeclared") added. I am submitting this as a bug rather than a feature because we considered the behavior up to v.0.11.10 as the feature because it allowed use of a common file and, by allowing new assignments without a corresponding variable declaration, provided a certain amount of forward- and backward-compatiblity.

Update

I am now deleting from terraform.tfvars every line that does not match the following regular expression in infrastructure.tf:

^[\s]*variable[\s]+\"$var\".*$"

So I am unblocked for the moment.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions