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

Backport of Handle move blocks within a module which is changing the index into v1.1 #30250

Merged

Conversation

teamterraform
Copy link
Contributor

Backport

This PR is auto-generated from #30232 to be assessed for backporting due to the inclusion of the label 1.1-backport.

The below text is copied from the body of the original PR.


When a move statement is only changing the index of a module, any moves within that module would result in cycles, because both the absolute From and To addresses would match both of the parent module's From and To address.

For example, changing the index of a module named count results in a a from->to of:

module.count->module.count[0]

And changing the count of a resource nested within module.count results in:

module.count[*].test.count->module.count[*].test.count[0]

Because module.count[*] matches both the From and To addresses of the parent, the edges would be added in both directions resulting in a cycle.

The graph we actually want in this case looks like

module.count->module.count[0]
module.count[*].test.count->module.count[*].test.count[0]
  module.count->module.count[0]

with a connection only from the inner move to the outer move, which matches the same order of operations when the outer module is changing the name entirely. We achieve this by checking if the dependent move statement is only changing the module index with a new from.MoveModuleReIndex(to) method, and skip adding the graph edge.

Fixes #30208

While not contributing to the cycle, it was noticed in #30208 that impliedMoveStatements was not correctly calling itself recursively, which is also fixed and tested by this PR.

@teamterraform teamterraform force-pushed the backport/jbardin/module-move-re-index/specially-calm-pipefish branch from 0569e8d to f7b6f80 Compare December 22, 2021 21:27
@jbardin jbardin merged commit be68340 into v1.1 Dec 22, 2021
@jbardin jbardin deleted the backport/jbardin/module-move-re-index/specially-calm-pipefish branch December 22, 2021 22:14
@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 Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants