fix: trigger cloudinit volume replacement on content change only - #8
Merged
Conversation
PR #7's replace_triggered_by on libvirt_cloudinit_disk didn't actually fix cross-host apply: when the local /tmp ISO is missing, the provider reports the disk as "deleted", tofu plans a "create" (not a "replace") for it, and replace_triggered_by does not fire on a create that follows drift detection. The dependent libvirt_volume.cloudinit then still planned an in-place url update and apply died on: Error: Update Not Supported Storage volumes cannot be updated. All changes require replacement. Switch the trigger to the cloud-init *content* itself, captured in a terraform_data resource that hashes the rendered meta_data/user_data/ network_config. The libvirt_volume.cloudinit now ignores changes to the volatile `create` block (the url that points at /tmp) and is only replaced when the content hash genuinely changes — which is what we actually want. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
PR #7's
replace_triggered_by = [libvirt_cloudinit_disk.commoninit]didn't actually fix cross-host applies. When the provider's local/tmpISO is missing on the apply host (CI runner vs. laptop, post-reboot/tmpwipe), the disk'sReadreturns "not found", tofu drops it from state, and the next plan shows the disk as created (not replaced).replace_triggered_bydoes not fire on a create-following-drift, so the dependentlibvirt_volume.cloudinitstill planned an in-placeurlupdate and apply died on:This change moves the trigger to the cloud-init content itself, captured in a
terraform_datawhoseinputissha256of the renderedmeta_data+user_data+network_config. The volume now:ignore_changes = [create]— absorbs the volatile/tmppath drift entirelyreplace_triggered_by = [terraform_data.cloudinit_content]— replaces only when cloud-init content has actually changedOne-time upgrade churn
On first apply for any existing consumer, the new
terraform_dataresource is created. Becausereplace_triggered_bytreats a create as a planned action, the existinglibvirt_volume.cloudinitwill be replaced once. That's a cdrom swap — harmless on running VMs (cloud-init only runs on first boot). After this one event, the volume is stable unless cloud-init content actually changes.Test plan
make test) greentfroot-libvirtplan no longer showslibvirt_volume.cloudinit ... will be updated in-placefollowed by an Update Not Supported error at apply🤖 Generated with Claude Code