Add variables to all commands that load configuration#38276
Merged
Conversation
61f3f54 to
fe56406
Compare
Instead of passing a "magic" boolean as third parameter, we now have two functions `ParseConstVariableValues` and `ParseVariableValues`.
We never want to stub const variables, so we will always try to get values for them. The cloud backend now always fetches variable values so const vars can be satisfied.
The new `resolveConstVariables` helper checks if const variables are present in the configuration, but don't have a value yet. In that case we try to fetch them via a backend. This will only work for backends that implement the ConstVariableSupplier interface. (Which the `cloud` backend does) The precedence is the same as for existing commands: a CLI supplied value will override a value from a workspace
* modules * providers * providers lock * providers mirror * validate * state mv * state pull * state push * state replace provider * state rm * taint * get
fe56406 to
c25adc4
Compare
DanielMSchmidt
approved these changes
Mar 17, 2026
| defer done() | ||
|
|
||
| path, err := ModulePath(cmdFlags.Args()) | ||
| path, err := ModulePath(nil) |
Contributor
There was a problem hiding this comment.
Why is this nill now when we added the args before?
Member
Author
There was a problem hiding this comment.
We now do the check for extra args in the arguments package. The ModulePath() call now is only used to get the path. I think in the long run we can fully replace it
| "github.com/hashicorp/terraform/internal/tfdiags" | ||
| ) | ||
|
|
||
| // ConstVariableSupplier is an optional interface that backends can implement |
Contributor
There was a problem hiding this comment.
We need to make sure to document this properly, could be confusing for people on the remote backend if their backend does not load the vars.
Member
Author
There was a problem hiding this comment.
Yeah, good point. I'll look for a good place to document this
3 tasks
3 tasks
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates most Terraform commands and lets them accept variables via the CLI or a backend.
The new
resolveConstVariableshelper checks if const variables are present in the configuration, but don't have a value yet. In that case we try to fetch them via a backend. This will only work for backends that implement the ConstVariableSupplier interface. (Which thecloudbackend does)The precedence is the same as for existing commands: a CLI supplied value will override a value from a workspace.
Review Notes: The commits allow stepping through the changes one by one
Target Release
1.15.x
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry