Repository navigation
fix(export): write a moved block when an exported resource is re-keyed - #200
Merged
Merged
Conversation
The id map records the label each id was exported under. When the same (type, id) now gets another label, imports.tf gets a moved block from the old address to the new one, so tofu plan no longer proposes destroying it. The import block for the new address stays: tofu moves first and the import of the same id is then a no-op, and when the old address never reached state the import still brings the resource in. Closes #199
…eadable id map
A swap of two keys, or a new resource taking over a renamed one's old key,
produced a moved block whose source is still declared, which tofu rejects
("Moved object still exists"). Those moves are now left out with an
EXPORT_MOVE_CONFLICT warning.
The move lookup made every export read the id map, so a corrupt map failed
a --no-ids export that never needed it. A map that does not load now costs
only the moves, with an EXPORT_MOVES_SKIPPED warning.
Member
Author
|
Review (
3 regression tests (fail before, pass after). Ran the built CLI end to end: re-key → moved block, swap → warning and no block, corrupt map + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #199
What
When a resource keeps its id but gets a new ct key,
ct export tfnow compares each id with the label the id map recorded and writes amoved { from = <old>, to = <new> }block at the top ofimports.tf. Before, the old address simply lost its config andtofu planproposed destroying it (or failed onprevent_destroy).Deviation from the issue: the import block stays
The issue suggested dropping the import block for a moved resource. That would plan a create (a duplicate) whenever the old address never reached tofu's state, e.g. an export that was never applied. Checked locally with OpenTofu 1.12.5 and
random_id:tofu planmoved+import0 to add, 0 to change, 0 to destroymoved+import1 to import, 0 to addSo both blocks are written, and both cases come out right.
Limitation (documented)
The id map is the only record of the old label. A default export also rewrites the map, so a second export before applying loses the
movedblock. Documented indocs/opentofu-migration.md: apply on each host before re-exporting, or export with--no-idsand refresh withct ids sync.Checks
lint,typecheck,test(1276 passed),buildall green locally; 4 new tests intests/export/export-tf.test.ts.