terraform console: Option to evaluate in a planned state#34342
Merged
apparentlymart merged 1 commit intomainfrom Dec 1, 2023
Merged
terraform console: Option to evaluate in a planned state#34342apparentlymart merged 1 commit intomainfrom
apparentlymart merged 1 commit intomainfrom
Conversation
97323a2 to
b649cba
Compare
alisdair
approved these changes
Dec 1, 2023
Contributor
alisdair
left a comment
There was a problem hiding this comment.
This is delightful! Just a tiny question inline.
Previously "terraform console" always evaluated in a kinda strange context where resource instance data comes from the prior state, but other derived of values end up being calculated dynamically based on the current configuration, which is okay for simple cases but can be confusing if the configuration has changed significantly since the most recent apply, or if there haven't yet been any applied changes. Now we'll allow an optional new mode where Terraform runs the normal plan phase (as if running "terraform plan") and then uses the resulting _planned state_ as the basis for evaluation, allowing evaluation against a partial approximation of what the world ought to look like if these changes were applied, without having to actually apply them first. As with the previous use of the eval walk, it's possible that an erroneous situation will still produce a partial evaluation scope, and so the console still allows evaluation against that scope but with a caveat that it might produce unexpected results. In practice this can be useful for debugging situations like when unknown values block planning of an object, to allow inspection of the values that are contributing to that blocked planning operation even though the plan is not yet complete.
b649cba to
ecb333d
Compare
Contributor
|
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
Contributor
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously
terraform consolealways evaluated in a kinda strange context where resource instance data comes from the prior state, but other derived of values end up being calculated dynamically based on the current configuration, which is okay for simple cases but can be confusing if the configuration has changed significantly since the most recent apply, or if there haven't yet been any applied changes.Now we'll allow an optional new mode where Terraform runs the normal plan phase (as if running
terraform plan) and then uses the resulting planned state as the basis for evaluation, allowing evaluation against a partial approximation of what the world ought to look like if these changes were applied, without having to actually apply them first.As with the previous use of the eval walk, it's possible that an erroneous situation will still produce a partial evaluation scope, and so the console still allows evaluation against that scope but with a caveat that it might produce unexpected results. In practice this can be useful for debugging situations like when unknown values block planning of an object, to allow inspection of the values that are contributing to that blocked planning operation even though the plan is not yet complete.
Working on #34338 yesterday, and realizing that the test language has requirements that are a mix of some requirements from the stacks language and some requirements from
terraform console, made me recall an old idea of allowingterraform consoleto run in the context of a generated plan as a way to have more information available in scope, and as an additional option for debugging situations where unknown values are ending up in unfortunate places.Since that PR already did most of the work to make this possible, this PR is a little extra value-add from #34338 to fill a little gap we've been hoping to fill for a long while now.
Here's an (admittedly rather contrived) example of using
terraform console -planin a configuration which cannot fully complete planning due to an unknown value in an inconvenient location:Although hopefully soon we'll finish working on #30937 and thus the question of where an unknown value originated will become less significant, I think it's still pretty helpful to be able to peek into the details of what values contributed to a plan, such as with the situations I was aiming to improve on in #34312: why is my postcondition failing? why is the provider proposing to replace this object?