core: Do not create "delete" changes for nonexistent outputs#31471
Merged
Conversation
If there are outputs in configuration, a destroy plan will always contain a "delete" change for each of these outputs. This leads to meaningless delete changes being present for outputs which were not present in state and therefore cannot be deleted. Since there is a change in the plan, this plan will then be considered applyable, and the user will be presented with text instructing them to apply a plan in which there are no actual changes. This commit stops the above from happening in the case of root module outputs.
ca3867a to
3081083
Compare
jbardin
reviewed
Jul 19, 2022
Member
jbardin
left a comment
There was a problem hiding this comment.
LGTM! These were never in there for any particular reason. Since outputs are always re-calculated during a plan, they were always added to the changes regardless of what that change was.
jbardin
approved these changes
Jul 19, 2022
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.
If there are outputs in configuration, a destroy plan will always contain a "delete" change for each of these outputs.
If an output was not present in state to begin with, the change will look like this:
Since there is a change in the plan, this plan will be considered applyable, and the user will be presented with text instructing them to apply a plan in which there are no actual changes.
Applying the destroy plan will not actually do anything, since the output was not in state to begin with.
This commit stops the above from happening in the case of root module outputs.
A simple example follows. For a more realistic example and the issue that motivated this change, please see #23387 (comment).
Example
Configuration
Steps
terraform initterraform plan -detailed-exitcode -destroyResult prior to change
Exit code 2.
Plan prior to change
{ "format_version": "1.1", "terraform_version": "1.3.0-dev", "planned_values": { "root_module": {} }, "output_changes": { "foo": { "actions": [ "delete" ], "before": null, "after": null, "after_unknown": false, "before_sensitive": false, "after_sensitive": false } }, "configuration": { "root_module": { "outputs": { "foo": { "expression": { "constant_value": null } } } } } }Result after change
Exit code 0.
Plan after change
{ "format_version": "1.1", "terraform_version": "1.3.0-dev", "planned_values": { "root_module": {} }, "configuration": { "root_module": { "outputs": { "foo": { "expression": { "constant_value": null } } } } } }