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

prevent cycles when connecting destroy nodes #31857

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Sep 23, 2022

When adding destroy edges between resources from different providers, and a provider itself depends on the other provider's resources, we can get cycles in the final dependency graph.

The problem is a little deeper than simply not connecting these nodes, since the edges are still needed when doing a full destroy operation. For now we can get by assuming the edges are required, and reverting them only if they result in a cycle. This works because destroy edges are the last edges added to managed resources during graph building.

This was rarely a problem before v1.3, because noop nodes were not added to the apply graph at all, and unused values were aggressively pruned. In v1.3 however all nodes are kept in the graph so that postcondition blocks are always evaluated during apply, increasing the chances of the cycles appearing.

Fixes #31843

Target Release

1.3.1

@jbardin jbardin added the 1.3-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Sep 23, 2022
@jbardin jbardin requested a review from a team September 23, 2022 18:16
@jbardin jbardin self-assigned this Sep 23, 2022
@jbardin jbardin force-pushed the jbardin/destroy-edge-cycles branch from a1e5af5 to abbfa0c Compare September 23, 2022 18:26
Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

The code change makes sense to me given the detailed explanation in the comments, thanks!

It might be worth expanding the comments in the test case to explain why the newly added objects cause a cycle without this change. It took me a bit of reading up to see from the inlined HCL config that the other provider references module.mod.

@apparentlymart apparentlymart added this to the v1.3.1 milestone Sep 26, 2022
When adding destroy edges between resources from different providers,
and a provider itself depends on the other provider's resources, we can
get cycles in the final dependency graph.

The problem is a little deeper than simply not connecting these nodes,
since the edges are still needed when doing a full destroy operation.
For now we can get by assuming the edges are required, and reverting
them only if they result in a cycle. This works because destroy edges
are the last edges added to managed resources during graph building.

This was rarely a problem before v1.3, because noop nodes were not added
to the apply graph, and unused values were aggressively pruned. In v1.3
however all nodes are kept in the graph so that postcondition blocks are
always evaluated during apply, increasing the chances of the cycles
appearing.
@jbardin jbardin force-pushed the jbardin/destroy-edge-cycles branch from abbfa0c to ce02344 Compare September 26, 2022 17:38
@jbardin jbardin merged commit 1c8352d into main Sep 26, 2022
@jbardin jbardin deleted the jbardin/destroy-edge-cycles branch September 26, 2022 18:23
@github-actions
Copy link
Contributor

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
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.
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 Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.3-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strange cycle errors in 1.3.0
3 participants