-
Notifications
You must be signed in to change notification settings - Fork 907
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
import
block might cause a destroy action to attempt destruction of an already-destroyed resource
#1803
Comments
I am working on this and will submit a PR |
going to submit a PR, Co-authored-by: @tony21921 |
I would perhaps describe this problem a little differently: The opentofu/internal/tofu/context_plan.go Lines 211 to 220 in d396502
The destroy mode in particular has an interesting quirk: it actually internally runs two plan phases, with the first in "normal" mode to make sure that the prior state represents the remote system as closely as possible, except that it sneakily sets the opentofu/internal/tofu/context_plan.go Lines 399 to 449 in d396502
If that succeeds, it then performs the "real" destroy-mode plan phase (with opentofu/internal/tofu/context_plan.go Lines 451 to 458 in d396502
The main handling of the planning mode happens during graph construction: opentofu/internal/tofu/context_plan.go Lines 840 to 893 in d396502
From reading the trace logs I've confirmed that the import is happening during that secret initial "normal mode" plan, when it visits the
Therefore it seems like probably the least invasive change would be to make the opentofu/internal/tofu/graph_builder_plan.go Lines 271 to 279 in d396502
The expansion node can then in turn skip resolving imports when its own "skip imports" flag is set: opentofu/internal/tofu/node_resource_plan.go Lines 329 to 377 in d396502
In an ideal world we wouldn't have this secret "normal-ish plan" hidden inside the destroy plan implementation with various little special cases attached to it, but it's risky to replace it because the destroy plan implementation is very focused only on the problem of generating "destroy" actions for objects in the state and so doesn't really know how to deal with anything else. |
I followed your approach, @apparentlymart. Thanks for your help! Let me know if you have a different opinion. |
OpenTofu Version
OpenTofu Configuration Files
Debug Output
.
Expected Behavior
When attempting to destroy the configuration, after
random_integer.a
has been destroyed as part of a targeted destroy, OpenTofu should attempt to only destroyrandom_integer.b
Actual Behavior
OpenTofu attempts to destroy both
random_integer.a
andrandom_integer.b
The logs you get from the
tofu destroy
action:It should only attempt to destroy
random_integer.b
Steps to Reproduce
tofu init
tofu apply
tofu destroy -target=random_integer.a
tofu destroy
Additional Context
No response
References
The text was updated successfully, but these errors were encountered: