-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Variables values get overridden from environment variables when applying a plan #36410
Comments
Reproduced, thanks for the repro case - I'll take a look into a fix. |
@radeksimko Perfect, Thank you for the quick fix! Do I understand it correctly that there is currently no released version which includes the fix and it will most likely included in version 1.11? |
It should be part of a 1.11 release next week, as we generally cut releases weekly. If you are constrained down to final releases then you may have to wait for a little longer. There are currently no plans to cut another 1.10 patch release but it should be relatively smooth upgrade between the two major versions as we generally follow the compatibility promises made for v1. On the note of the fix - just to set expectations right - attempting to override variables like you described is something we always considered an anti-pattern but it was silently ignored in the past before v1.10. The fix does two things - it corrects the diagnostic wording to not imply mixed source ordering anymore and "downgrades" the new diagnostic specific to All that is to say that the best way of working around this and the best long-term solution in general is to avoid passing |
That's fine. We can wait for the 1.11 release.
That is interesting to know. I was not aware of that until now. Thanks for the clarification.
TF_VAR_ variables to the apply runs |
That would be one solution. I was more implying that Technically you should not need the configuration for the I like to think that separating environments between jobs in the same sequence is a bit easier though. For example, in GitHub Actions I assume you would model each (plan/apply) phase as a separate job and then each job can declare its own On a related note, the recent introduction of ephemeral values also builds on this assumption/principle. It allows you to build workflows where plan and apply each intentionally receive different (ephemeral) values. This may include credentials - e.g. you may not need write access to produce the plan so you can pass read-only credentials. So that makes easier to achieve the principle of least privilege. Relatedly - if you do have valid reasons for variables to differ between plan and apply you should declare those as ephemeral and then you can pass them via |
Terraform Version
Terraform Configuration Files
main.tf:
test.tfvars.
Debug Output
Expected Behavior
Terraform apply should apply the plan as expected using only the values already in the planned file and not tries to override them.
Actual Behavior
It tries to override with entries from the environment variable and then fails with:
In additional the values seem to be mixed up in the error message. According to this: override with entries from terraform.tfvars variables defined by
-var-file
would override the value from the environment variable. Consequently the "The saved plan specifies" should be "set by test.tfvars" and "value whereas during apply the value" should be "set by env var" (the value which is actually set by the environment variable).How the message is currently it says the exact opposite which is wrong. ("set by test.tfvars" is not set by environment variabel but by test.tfvars).
Steps to Reproduce
Additional Context
No response
References
Similar to #36177 but instead for auto-loaded files it happens with environment variables (too).
Generative AI / LLM assisted development?
N/A
The text was updated successfully, but these errors were encountered: