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

Evaluate resource preconditions and postconditions during apply even if they have no planned change #31491

Merged
merged 2 commits into from Jul 22, 2022

Conversation

apparentlymart
Copy link
Member

@apparentlymart apparentlymart commented Jul 21, 2022

Preconditions and postconditions results can change due to changes to other upstream resources, even if the resource they are directly attached to doesn't have a change pending.

Therefore we need to still visit "no-op" resources during the apply walk and deal with the ancillary side-effects, skipping only the actual call to the provider to run ApplyResourceChange. If we don't, there can potentially be failures we won't catch until the next plan, which might be run by someone who has no context about whatever change broke the conditions.

This also makes the UI "see" no-op changes being applied via the hooks API. Rather than making another special case in Terraform Core for that, I concluded it's a UI-level concern to decide whether it's interesting to report a particular resource being "skipped" and so I put the special case in the UI layer instead.

Fixes #31261.

We previously would optimize away the graph nodes for any resource
instance without a real change pending, but that means we don't get an
opportunity to re-check any invariants associated with the instance, such
as preconditions and postconditions.

Other upstream changes during apply can potentially decide the outcome of
a condition even if the instance itself isn't being changed, so we do
still need to revisit these during apply or else we might skip running
certain checks altogether, if they yielded unknown results during planning
and then don't get run during apply.
Previously we tried to early-exit before doing anything at all for any
no-op changes, but that means we also skip some ancillary steps like
evaluating any preconditions/postconditions.

Now we'll skip only the main action itself for plans.NoOp, and still run
through all of the other side-steps.

Since one of those other steps is emitting events through the hooks
interface, this means that now no-op actions are visible to hooks, whereas
before we always filtered them out before calling. I therefore added some
additional logic to the hooks to filter them out at the UI layer instead;
the decision for whether or not to report that we visited a particular
object and found no action required seems defensible as a UI-level concern
anyway.
@apparentlymart apparentlymart merged commit 72dd14c into main Jul 22, 2022
@apparentlymart apparentlymart deleted the f-apply-noop-conditions branch July 22, 2022 22:27
@github-actions
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants