Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow moving instances to new resources #23582

Merged
merged 1 commit into from
Dec 5, 2019
Merged

Allow moving instances to new resources #23582

merged 1 commit into from
Dec 5, 2019

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Dec 5, 2019

If a state mv target happens to be a resource that doesn't exist, allow
the creation of the new resource inferring the EachMode from the target
address.

Fixes #22301
Fixes #23569
Fixes #23497

@jbardin jbardin requested a review from a team December 5, 2019 21:37
Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

Nice!

Some thoughts inline, but subjective things so I don't mean to block if you disagree with them.

))
c.showDiagnostics(diags)
return 1
fromEachMode = eachModeForInstanceKey(addrTo.Resource.Key)
}

resourceAddr := addrTo.ContainingResource()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to do anything special here for the situation where the target resource address is in a module that doesn't exist in the state yet? I don't recall if SyncWrapper().SetResourceMeta handles automatically creating the module shell in that case; if it does, I think it could help to note that specifically in a comment here to aid future maintainers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, moving to a new module already works correctly. I'm going to double check that we have that in a test, or update this one to cover it.

))
c.showDiagnostics(diags)
return 1
fromEachMode = eachModeForInstanceKey(addrTo.Resource.Key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could/should we use the configuration as a safety check here to make sure the user is asking for something sensible? By which I mean, if there's no configuration block at the target resource at all then maybe we still fail, and likewise if the set-ness of the count or for_each of that resource disagrees with the selected each mode we could fail that too.

That would help make sure that a typo doesn't lead to moving the instance somewhere that would cause it to be immediately destroyed as an "orphan" on the next apply. That'd be consistent with our rule that you can't terraform import into a resource that isn't present in the configuration, so maybe there's some existing logic over there we could borrow and generalize to ensure they both follow the same rules.

Copy link
Member Author

Choose a reason for hiding this comment

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

We actually don't handle config or prevent any of these sorts of things at all at the moment, so I think that's a question for a much larger change. Seeing how the normal workflow is to verify the change with a plan, I don't think typos will be too disastrous. Allowing individual instances to be moved also makes fixing any typos much easier as well.

If a state mv target happens to be a resource that doesn't exist, allow
the creation of the new resource inferring the EachMode from the target
address.
@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 28, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
2 participants