Skip to content
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

stacks: allow unknown variables during apply operations #36311

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

liamcervante
Copy link
Member

An assumption was made in Stacks that unknown variables should not be available at all during apply operations. This assumption was not true - we can have unknown values during refresh, destroy and deferred operations.

This PR removes the part of Stacks that was skipping components that found unknown variables - this was causing endless loops of undestroyable configuration in practice.

This PR also updates the part where variables are loaded for components to allow a specific error to result in a completely unapplyable component. This is the case where a variable has changed between the plan and apply operations. Previously, this was resulting in an unknown value that was just leaving the component to be skipped. Now, we aren't skipping that component anymore so we need to find a way to make that error stronger. This does result in an extra diagnostic being written in this specific error case, but as this error represents a problem in Terraform we should hopefully never see this case in practice.

A side effect of this, is that components with unknown variables now return slightly more complete state updates which has resulted in several tests being updated.

@liamcervante liamcervante requested a review from a team as a code owner January 13, 2025 09:22

sort.SliceStable(applyDiags, diagnosticSortFunc(applyDiags))
expectDiagnosticsForTest(t, applyDiags,
expectDiagnostic(
tfdiags.Error,
"Inconsistent value for input variable during apply",
"The value for non-ephemeral input variable \"input\" was set to a different value during apply than was set during plan. Only ephemeral input variables can change between the plan and apply phases."),
expectDiagnostic(tfdiags.Error, "Invalid inputs for component", "Invalid input variable definition object: attribute \"input\": string required."),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the extra diagnostic discussed in the description. This is the diagnostic that now prevents the bad component from actually applying.

@@ -3110,16 +3117,14 @@ func TestApplyWithChangedInputValues(t *testing.T) {

go Apply(ctx, &applyReq, &applyResp)
applyChanges, applyDiags := collectApplyOutput(applyChangesCh, diagsCh)
if len(applyDiags) != 1 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was redundant, we also check the diagnostics on line 3121, so doing it twice was pointless.

@ker-an
Copy link

ker-an commented Jan 13, 2025

Jira ticket created by Sarah: https://hashicorp.atlassian.net/browse/TF-23317

Copy link
Member

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic checks out, and the test case is an accurate reduction of what I understood about how to reproduce the bug we saw.

As mentioned in #36310, I tested a combination of the two PRs, and was able to fully destroy a stack that errored during apply on the first destroy attempt.

@liamcervante liamcervante added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label Jan 17, 2025
@liamcervante liamcervante merged commit 1c04516 into main Jan 20, 2025
9 checks passed
@liamcervante liamcervante deleted the liamcervante/stacks-destroy-two branch January 20, 2025 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog-needed Add this to your PR if the change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants