Repository navigation
Record lifecycle.prevent_destroy in state so removed resources stay protected - #7499
Open
andrewnester wants to merge 4 commits into
Open
andrewnester wants to merge 4 commits into
andrewnester wants to merge 4 commits into
Conversation
A resource with lifecycle.prevent_destroy: true was deleted as soon as it was removed from the configuration: checkForPreventDestroy only read the flag from the current configuration, so a resource that is only in the state was never checked, and the state did not record the flag either. Record the flag with each state entry (resources.json and the DMS envelope) and carry it in the plan: from the configuration for declared resources, from the state for delete entries of removed ones. A toggle of the flag on an otherwise unchanged resource plans as skip with prevent_destroy_changed set; applying it rewrites the state entry without a backend call, and with deployment history it is staged and recorded as an update, since every recorded write must map to a staged operation. The check then refuses, for both deploy and destroy, to delete a resource that is only in the state and was last deployed with the flag. To delete it, add it back with prevent_destroy: false, deploy, and remove it again. Resources still in the configuration are governed by the configured value, as before. Fixes #4872 Co-authored-by: Isaac <no-reply@databricks.com>
andrewnester
marked this pull request as ready for review
November 11, 2026 18:09
andrewnester
requested review from
anton-107,
denik,
janniklasrose and
pietern
and removed request for
anton-107
November 11, 2026 18:09
Contributor
|
Commit: Regression test reportSelected 2 changed tests (limit=20, 0 not selected) 3 tests: regression=3 unreleased=0 coverage=0 failing=0
TestAccept/bundle/dms/prevent-destroy/DMS=true: branch ✅ | main (eef3b54) ❌ | latest (v1.26.0) ❌main (eef3b54): latest (v1.26.0): same output as main (eef3b54) TestAccept/bundle/lifecycle/prevent-destroy/DMS=: branch ✅ | main (eef3b54) ❌ | latest (v1.26.0) ❌main (eef3b54): latest (v1.26.0): same output as main (eef3b54) TestAccept/bundle/lifecycle/prevent-destroy/DMS=true: branch ✅ | main (eef3b54) ❌ | latest (v1.26.0) ❌main (eef3b54): latest (v1.26.0): same output as main (eef3b54) |
Collaborator
✅ Integration test reportCommit: bb7c21c
Top 11 slowest tests (at least 2 minutes):
|
This branch has not been deployed
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.
Changes
Fixes #4872.
lifecycle.prevent_destroynow also protects a resource after it is removed from the configuration:bundle deployandbundle destroyrefuse to delete it and name the escape hatch (add it back withprevent_destroy: false, deploy, then remove it).Why
The check only read the flag from the current configuration, so a removed resource was never checked and was deleted. That mirrored Terraform but defeated the flag's purpose.
Tests
Updated
acceptance/bundle/lifecycle/prevent-destroy(removal refused, escape hatch succeeds, both DMS variants), newacceptance/bundle/dms/prevent-destroy, and unit tests for the state round trip, the rewrite and the new check branch.This PR was written by Claude Code.
This pull request and its description were written by Isaac.