diff --git a/.nextchanges/bundles/report-removed-from-state.md b/.nextchanges/bundles/report-removed-from-state.md new file mode 100644 index 00000000000..d5936a440a1 --- /dev/null +++ b/.nextchanges/bundles/report-removed-from-state.md @@ -0,0 +1 @@ +* Report resources removed from bundle state after ignored deletion errors separately from deleted resources in bundle `deploy` and `destroy` output. ([#7496](https://github.com/databricks/cli/pull/7496)) diff --git a/acceptance/bundle/deploy/summary-on-error/databricks-empty.yml b/acceptance/bundle/deploy/summary-on-error/databricks-empty.yml new file mode 100644 index 00000000000..7ca67ba1e75 --- /dev/null +++ b/acceptance/bundle/deploy/summary-on-error/databricks-empty.yml @@ -0,0 +1,2 @@ +bundle: + name: test-deploy-summary-on-error diff --git a/acceptance/bundle/deploy/summary-on-error/output.txt b/acceptance/bundle/deploy/summary-on-error/output.txt index da8dd2ecb44..32ecbc40a98 100644 --- a/acceptance/bundle/deploy/summary-on-error/output.txt +++ b/acceptance/bundle/deploy/summary-on-error/output.txt @@ -15,5 +15,21 @@ API message: Fault injected by test. Error: cannot create resources.jobs.job_03: dependency failed: resources.jobs.job_02 -Files: 1 uploaded, 0 deleted +Files: 2 uploaded, 0 deleted Resources: 1 created, 0 changed, 0 deleted, 0 unchanged, 2 failed + +=== Removing a resource whose delete is denied reports state removal + +>>> fault.py POST /api/2.2/jobs/delete 403 0 1 PERMISSION_DENIED + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-deploy-summary-on-error/default/files... +Warn: destroying resources.jobs.job_01: Ignoring permission error when deleting resources.jobs.job_01 id=[JOB_01_ID]: Fault injected by test. +Removed jobs.job_01 from state +Files: 1 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 0 unchanged, 1 removed from state + +>>> [CLI] jobs get [JOB_01_ID] +{ + "name": "job-01" +} diff --git a/acceptance/bundle/deploy/summary-on-error/script b/acceptance/bundle/deploy/summary-on-error/script index 6ce82e64857..e88f1afa7c3 100644 --- a/acceptance/bundle/deploy/summary-on-error/script +++ b/acceptance/bundle/deploy/summary-on-error/script @@ -4,3 +4,10 @@ title "Deploy three chained jobs; the second create fails" # reports the accurate counts (1 created, 2 failed) rather than the planned 3 created. trace fault.py "POST /api/2.2/jobs/create" 400 1 1 INVALID_PARAMETER_VALUE trace musterr $CLI bundle deploy + +title "Removing a resource whose delete is denied reports state removal" +job_id=$(read_id.py job_01) +cp databricks-empty.yml databricks.yml +trace fault.py "POST /api/2.2/jobs/delete" 403 0 1 PERMISSION_DENIED +trace $CLI bundle deploy +trace $CLI jobs get "$job_id" | jq '{name: .settings.name}' diff --git a/acceptance/bundle/destroy/summary-on-error/output.txt b/acceptance/bundle/destroy/summary-on-error/output.txt index 8ca81255cf6..73a6b4b4553 100644 --- a/acceptance/bundle/destroy/summary-on-error/output.txt +++ b/acceptance/bundle/destroy/summary-on-error/output.txt @@ -29,3 +29,49 @@ API error_code: INVALID_PARAMETER_VALUE API message: Fault injected by test. Destroy: 2 deleted, 1 failed + +=== A permission-denied delete removes state without reporting a deletion + +>>> fault.py POST /api/2.2/jobs/delete 403 0 1 PERMISSION_DENIED + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.job_01 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-destroy-summary-on-error/default + +Warn: destroying resources.jobs.job_01: Ignoring permission error when deleting resources.jobs.job_01 id=[JOB_01_ID]: Fault injected by test. +Destroy: 0 deleted, 1 removed from state + +>>> [CLI] jobs get [JOB_01_ID] +{ + "name": "job-01" +} + +=== Without deployment history, ignored delete errors also report state removal + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-destroy-summary-on-error/default/files... +Created jobs.job_01 +Created jobs.job_02 +Created jobs.job_03 +Files: 1 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +>>> fault.py POST /api/2.2/jobs/delete 400 2 1 INVALID_PARAMETER_VALUE + +>>> [CLI] bundle destroy --auto-approve +The following resources will be deleted: + delete resources.jobs.job_01 + delete resources.jobs.job_02 + delete resources.jobs.job_03 + +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-destroy-summary-on-error/default + +Warn: destroying resources.jobs.job_01: Ignoring error when deleting resources.jobs.job_01 id=[JOB_01_ID_3]: Fault injected by test. +Destroy: 2 deleted, 1 removed from state + +>>> [CLI] jobs get [JOB_01_ID_3] +{ + "name": "job-01" +} diff --git a/acceptance/bundle/destroy/summary-on-error/script b/acceptance/bundle/destroy/summary-on-error/script index d60c2335474..5bc99425c44 100644 --- a/acceptance/bundle/destroy/summary-on-error/script +++ b/acceptance/bundle/destroy/summary-on-error/script @@ -2,6 +2,7 @@ title "Deploy three chained jobs" trace $CLI bundle deploy # Mask the job IDs (the destroy error below prints job_01's) so the golden is stable. replace_ids.py +job_id=$(read_id.py job_01) title "Destroy: report two successful deletions and one failure" # Deletes run children-first (job_03, job_02, job_01); faulting the third makes only @@ -9,3 +10,18 @@ title "Destroy: report two successful deletions and one failure" # report those completed deletions even though destroy returns an error. trace fault.py "POST /api/2.2/jobs/delete" 400 2 1 INVALID_PARAMETER_VALUE trace musterr $CLI bundle destroy --auto-approve + +title "A permission-denied delete removes state without reporting a deletion" +trace fault.py "POST /api/2.2/jobs/delete" 403 0 1 PERMISSION_DENIED +trace $CLI bundle destroy --auto-approve +trace $CLI jobs get "$job_id" | jq '{name: .settings.name}' + +title "Without deployment history, ignored delete errors also report state removal" +# The previous destroy removed the deployment, so this starts fresh without history. +export DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY=false +trace $CLI bundle deploy +replace_ids.py +job_id=$(read_id.py job_01) +trace fault.py "POST /api/2.2/jobs/delete" 400 2 1 INVALID_PARAMETER_VALUE +trace $CLI bundle destroy --auto-approve +trace $CLI jobs get "$job_id" | jq '{name: .settings.name}' diff --git a/acceptance/bundle/destroy/summary-on-error/test.toml b/acceptance/bundle/destroy/summary-on-error/test.toml index dba94a9b922..7dad6e75d65 100644 --- a/acceptance/bundle/destroy/summary-on-error/test.toml +++ b/acceptance/bundle/destroy/summary-on-error/test.toml @@ -1,8 +1,8 @@ # fault.py registers its rule on the fake server, which a real workspace does not have. Cloud = false -# A failed resource delete only surfaces as a destroy error with deployment -# history enabled, so pin that variant to exercise the error path deterministically. +# Start with history enabled to surface a delete error; the script also exercises +# ignored delete errors after disabling history for a fresh deployment. EnvMatrix.DMS = ["true"] Ignore = [".databricks"] diff --git a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt index 96e016564df..651ab18f17c 100644 --- a/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt +++ b/acceptance/bundle/resources/materialization_sets/settled_failure/output.txt @@ -55,4 +55,5 @@ Deleting a Feature View that a FeatureSpec serves is not blocked, and leaves the All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-matset-settled-[UNIQUE_NAME]/default -Destroy: 3 deleted +Warn: destroying resources.materialization_sets.set1: Ignoring error when deleting resources.materialization_sets.set1 id=[UUID][0]: materialization set [UUID][0]: operation failed: [INTERNAL_ERROR] Deleted 0 of 2 materialized features in materialization set '[UUID][0]'. The operation's progress lists which deletion succeeded, which failed and why.; members left unchanged: [UUID][1] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][1]'. If the issue persists, please retry or contact support.; [UUID][2] (INTERNAL_ERROR): Failed to delete materialized feature '[UUID][2]'. If the issue persists, please retry or contact support. +Destroy: 2 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/out.destroy.txt b/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/out.destroy.txt index f770ebfac73..edc9c9eddfc 100644 --- a/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/out.destroy.txt +++ b/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/with_permissions/out.destroy.txt @@ -7,4 +7,4 @@ The following resources will be deleted: All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/default Warn: destroying resources.jobs.foo: Ignoring permission error when deleting resources.jobs.foo id=[FOO_ID]: User [TEST_SP_APPLICATION_ID] does not have Admin or Owner permissions on job [FOO_ID] -Destroy: 1 deleted +Destroy: 0 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/out.destroy.txt b/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/out.destroy.txt index f770ebfac73..edc9c9eddfc 100644 --- a/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/out.destroy.txt +++ b/acceptance/bundle/resources/permissions/jobs/destroy_without_mgmtperms/without_permissions/out.destroy.txt @@ -7,4 +7,4 @@ The following resources will be deleted: All files and directories at the following location will be deleted: /Workspace/Users/[TEST_SP_APPLICATION_ID]/.bundle/test-bundle-[UNIQUE_NAME]/default Warn: destroying resources.jobs.foo: Ignoring permission error when deleting resources.jobs.foo id=[FOO_ID]: User [TEST_SP_APPLICATION_ID] does not have Admin or Owner permissions on job [FOO_ID] -Destroy: 1 deleted +Destroy: 0 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_branches/replace_existing/out.destroy.txt b/acceptance/bundle/resources/postgres_branches/replace_existing/out.destroy.txt index 100e0a9a4b6..cefcfeb5e6b 100644 --- a/acceptance/bundle/resources/postgres_branches/replace_existing/out.destroy.txt +++ b/acceptance/bundle/resources/postgres_branches/replace_existing/out.destroy.txt @@ -12,4 +12,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-postgres-replace-branch-[UNIQUE_NAME]/default -Destroy: 2 deleted +Destroy: 1 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_data_apis/basic/output.txt b/acceptance/bundle/resources/postgres_data_apis/basic/output.txt index a8ee6145b38..0716b0c2962 100644 --- a/acceptance/bundle/resources/postgres_data_apis/basic/output.txt +++ b/acceptance/bundle/resources/postgres_data_apis/basic/output.txt @@ -137,4 +137,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-pg-data-api-[UNIQUE_NAME]/default -Destroy: 4 deleted +Destroy: 3 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_data_apis/out-of-band/output.txt b/acceptance/bundle/resources/postgres_data_apis/out-of-band/output.txt index ccaa335d2af..1412ed852e2 100644 --- a/acceptance/bundle/resources/postgres_data_apis/out-of-band/output.txt +++ b/acceptance/bundle/resources/postgres_data_apis/out-of-band/output.txt @@ -128,4 +128,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/oob-pg-data-api-[UNIQUE_NAME]/default -Destroy: 5 deleted +Destroy: 4 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_data_apis/recreate/output.txt b/acceptance/bundle/resources/postgres_data_apis/recreate/output.txt index 65346bbb2df..19da26029bb 100644 --- a/acceptance/bundle/resources/postgres_data_apis/recreate/output.txt +++ b/acceptance/bundle/resources/postgres_data_apis/recreate/output.txt @@ -84,4 +84,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/recreate-pg-data-api-[UNIQUE_NAME]/default -Destroy: 6 deleted +Destroy: 5 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_data_apis/update/output.txt b/acceptance/bundle/resources/postgres_data_apis/update/output.txt index 0b0e758cea9..2ede25482c8 100644 --- a/acceptance/bundle/resources/postgres_data_apis/update/output.txt +++ b/acceptance/bundle/resources/postgres_data_apis/update/output.txt @@ -98,4 +98,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/update-pg-data-api-[UNIQUE_NAME]/default -Destroy: 5 deleted +Destroy: 4 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_data_apis/url_reference/output.txt b/acceptance/bundle/resources/postgres_data_apis/url_reference/output.txt index 05549b12d5b..b36d583c8f2 100644 --- a/acceptance/bundle/resources/postgres_data_apis/url_reference/output.txt +++ b/acceptance/bundle/resources/postgres_data_apis/url_reference/output.txt @@ -76,4 +76,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/url-ref-pg-data-api-[UNIQUE_NAME]/default -Destroy: 6 deleted +Destroy: 5 deleted, 1 removed from state diff --git a/acceptance/bundle/resources/postgres_endpoints/replace_existing/out.destroy.txt b/acceptance/bundle/resources/postgres_endpoints/replace_existing/out.destroy.txt index 58f199c143a..7256a2079e6 100644 --- a/acceptance/bundle/resources/postgres_endpoints/replace_existing/out.destroy.txt +++ b/acceptance/bundle/resources/postgres_endpoints/replace_existing/out.destroy.txt @@ -13,4 +13,4 @@ All data stored in them will be permanently lost: All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-postgres-replace-endpoint-[UNIQUE_NAME]/default -Destroy: 3 deleted +Destroy: 2 deleted, 1 removed from state diff --git a/bundle/deployplan/action.go b/bundle/deployplan/action.go index 830511ac383..1df4e80e5c6 100644 --- a/bundle/deployplan/action.go +++ b/bundle/deployplan/action.go @@ -16,9 +16,11 @@ type Action struct { // because the resource implements no DoDelete, including during a recreate. StateOnly bool // Attempted and Applied mirror the same PlanEntry fields: Attempted means Apply - // reached this resource, Applied means its operation completed. + // reached this resource, Applied means its operation completed (including unbinding). Attempted bool Applied bool + // Unbound mirrors PlanEntry.Unbound: only the state entry was removed. + Unbound bool } func (a Action) String() string { diff --git a/bundle/deployplan/plan.go b/bundle/deployplan/plan.go index 56cdd174bc3..bc6fa85ca9e 100644 --- a/bundle/deployplan/plan.go +++ b/bundle/deployplan/plan.go @@ -82,10 +82,12 @@ func (p *Plan) CountActions() ActionCounts { return c } -// AppliedCounts reports completed operations and failed attempts. +// AppliedCounts reports completed operations, failed attempts, and resources +// removed from state without confirmed remote deletion. type AppliedCounts struct { ActionCounts - Failed int + Failed int + Unbound int } // CountApplied tallies the plan by outcome rather than by plan: a create/change/delete @@ -94,7 +96,7 @@ type AppliedCounts struct { // skipped it) is counted as Failed, and one Apply never reached is counted as neither. // Skips are unchanged regardless, since they run no backend operation; state-only deletes // are excluded entirely, matching CountActions. A failed recreate can still count a -// completed deletion. +// completed deletion, and ignored delete errors count as Unbound instead of Delete. func (p *Plan) CountApplied() AppliedCounts { var c AppliedCounts for _, entry := range p.Plan { @@ -115,9 +117,12 @@ func (p *Plan) CountApplied() AppliedCounts { if entry.IsStateOnlyDelete() { continue } - if entry.Applied { + if entry.Unbound { + c.Unbound++ + } else if entry.Applied { c.Delete++ - } else if entry.Attempted { + } + if entry.Attempted && !entry.Applied { c.Failed++ } case Recreate: @@ -194,7 +199,7 @@ type PlanEntry struct { Changes Changes `json:"changes,omitempty"` // Attempted is set when Apply starts processing this entry (the apply graph ran and - // reached this node); Applied is set when its operation completes. Both + // reached this node); Applied is set when its operation completes, including unbinding. Both // are runtime-only (never serialized). Together they let the deploy/destroy summaries // report what actually happened - applied, or attempted-but-failed - rather than the // planned count. An entry Apply never reached (e.g. a config error bailed out before @@ -204,6 +209,9 @@ type PlanEntry struct { // RecreateDeleted records completion of a recreate's backend delete step, even if // creating the replacement subsequently fails. RecreateDeleted bool `json:"-"` + // Unbound means a delete only removed the state entry: the API rejected the + // delete and the engine ignored that error without confirming remote deletion. + Unbound bool `json:"-"` } // IsStateOnlyDelete reports whether applying this delete only drops the state entry @@ -309,6 +317,7 @@ func (p *Plan) GetActions() []Action { StateOnly: entry.StateOnly, Attempted: entry.Attempted, Applied: entry.Applied, + Unbound: entry.Unbound, }) } diff --git a/bundle/deployplan/plan_test.go b/bundle/deployplan/plan_test.go index 063a42365d7..2a048965228 100644 --- a/bundle/deployplan/plan_test.go +++ b/bundle/deployplan/plan_test.go @@ -112,6 +112,16 @@ func TestCountApplied(t *testing.T) { entry: deployplan.PlanEntry{Action: deployplan.Delete, Attempted: true}, want: deployplan.AppliedCounts{Failed: 1}, }, + { + name: "ignored delete error only removes state", + entry: deployplan.PlanEntry{Action: deployplan.Delete, Attempted: true, Applied: true, Unbound: true}, + want: deployplan.AppliedCounts{Unbound: 1}, + }, + { + name: "wait failure after unbinding still reports state removal", + entry: deployplan.PlanEntry{Action: deployplan.Delete, Attempted: true, Unbound: true}, + want: deployplan.AppliedCounts{Unbound: 1, Failed: 1}, + }, { name: "state-only delete is excluded", entry: deployplan.PlanEntry{Action: deployplan.Delete, StateOnly: true, Attempted: true}, diff --git a/bundle/direct/apply.go b/bundle/direct/apply.go index 39384d9a79e..8f438ec66ed 100644 --- a/bundle/direct/apply.go +++ b/bundle/direct/apply.go @@ -21,7 +21,7 @@ func (d *DeploymentUnit) withResourceKey(ctx context.Context) context.Context { return dresources.WithResourceKey(ctx, strings.TrimPrefix(d.ResourceKey, "resources.")) } -func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState) error { +func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState, entry *deployplan.PlanEntry) error { ctx = log.WithPrefix(ctx, "destroying "+d.ResourceKey) ctx = d.withResourceKey(ctx) id := db.GetResourceID(d.ResourceKey) @@ -30,7 +30,7 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState return nil } - return d.Delete(ctx, db, id) + return d.Delete(ctx, db, id, entry) } func (d *DeploymentUnit) Deploy(ctx context.Context, db *dstate.DeploymentState, newState any, actionType deployplan.ActionType, planEntry *deployplan.PlanEntry) error { @@ -261,19 +261,22 @@ func (d *DeploymentUnit) UpdateWithID(ctx context.Context, db *dstate.Deployment return nil } -func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, oldID string) error { +func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, oldID string, entry *deployplan.PlanEntry) error { oldState, err := d.loadPersistedState(db) if err != nil { return err } err = d.Adapter.DoDelete(ctx, oldID, oldState) + // A parent-managed resource may remain if its parent is kept or fails to delete. + unbound := isManagedByParent(err) if err != nil && !apierr.IsMissing(err) && !isManagedByParent(err) { // Rather than failing delete and requiring user to unbind, we perform unbind automatically there. // Some services, e.g. jobs, return 403 for missing resources if caller did not have permissions to it when job existed. // In those cases 403 hides 404. In other cases, user not having permissions to resource but having in the bundle might // mean configuration error that user is trying to fix by removing resource from their bundle. if errors.Is(err, apierr.ErrPermissionDenied) { + unbound = true log.Warnf(ctx, "Ignoring permission error when deleting %s id=%s: %s", d.ResourceKey, oldID, err) } else if d.deleteConfirmedGone(ctx, oldID) { log.Warnf(ctx, "Treating %s id=%s as already deleted despite delete error: %s", d.ResourceKey, oldID, err) @@ -282,6 +285,9 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, err = fmt.Errorf("deleting id=%s: %w", oldID, err) db.RecordFailure(d.ResourceKey, oldID, err) return err + } else { + unbound = true + log.Warnf(ctx, "Ignoring error when deleting %s id=%s: %s", d.ResourceKey, oldID, err) } } @@ -289,6 +295,7 @@ func (d *DeploymentUnit) Delete(ctx context.Context, db *dstate.DeploymentState, if err != nil { return fmt.Errorf("deleting state id=%s: %w", oldID, err) } + entry.Unbound = unbound // Wait for asynchronous teardown after dropping state. Mirrors Recreate so // the contract is the same regardless of whether the user triggered diff --git a/bundle/direct/bundle_apply.go b/bundle/direct/bundle_apply.go index 5bebd99ecd1..cc3463d6890 100644 --- a/bundle/direct/bundle_apply.go +++ b/bundle/direct/bundle_apply.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "strings" "time" "github.com/databricks/cli/bundle/config" @@ -126,7 +127,7 @@ func (b *DeploymentBundle) Apply(ctx context.Context, client *databricks.Workspa // without calling the delete API. err = b.StateDB.DeleteState(ctx, resourceKey, false) } else { - err = d.Destroy(ctx, &b.StateDB) + err = d.Destroy(ctx, &b.StateDB, entry) } if err != nil { logdiag.LogError(ctx, fmt.Errorf("%s: %w", errorPrefix, err)) @@ -135,7 +136,11 @@ func (b *DeploymentBundle) Apply(ctx context.Context, client *databricks.Workspa // A state-only delete performs no backend operation, so don't report it, // consistent with the plan and apply summaries. if reportApplied && !entry.IsStateOnlyDelete() { - cmdio.LogString(ctx, deployplan.AppliedLine(resourceKey, action)) + if entry.Unbound { + cmdio.LogString(ctx, "Removed "+strings.TrimPrefix(resourceKey, "resources.")+" from state") + } else { + cmdio.LogString(ctx, deployplan.AppliedLine(resourceKey, action)) + } } entry.Applied = true return true diff --git a/bundle/phases/deploy.go b/bundle/phases/deploy.go index a3e73d6e292..65def0f89e7 100644 --- a/bundle/phases/deploy.go +++ b/bundle/phases/deploy.go @@ -137,6 +137,9 @@ func logDeploySummary(ctx context.Context, b *bundle.Bundle, plan *deployplan.Pl if counts.Failed > 0 { summary += fmt.Sprintf(", %d failed", counts.Failed) } + if counts.Unbound > 0 { + summary += fmt.Sprintf(", %d removed from state", counts.Unbound) + } // Gate on the plan's own NotSelected (not b.Select) so the suffix survives a // deploy from a --plan file, where --select was applied at plan time and // b.Select is empty here. NotSelected is only ever set by FilterToSelected. diff --git a/bundle/phases/destroy.go b/bundle/phases/destroy.go index 8ca6fe9c54b..12fd26a8de9 100644 --- a/bundle/phases/destroy.go +++ b/bundle/phases/destroy.go @@ -138,23 +138,26 @@ func approvalForDestroy(ctx context.Context, b *bundle.Bundle, plan *deployplan. return cmdio.AskYesOrNo(ctx, "Would you like to proceed?") } -// logDestroySummary reports completed deletions and failed attempts. +// logDestroySummary reports deletions, failures, and resources removed only from state. // Called even on error, since partial deletions may have succeeded. func logDestroySummary(ctx context.Context, b *bundle.Bundle, plan *deployplan.Plan) { if b.Quiet < bundle.QuietAll { // Count top-level resources only, matching the approval list above (which // skips children). Gone resources are excluded to match that list: they were // already deleted remotely, so applying their Delete only cleans up stale - // state and is not a destruction to report. Attempted operations that did not - // complete count as failed. - deleted, failed := 0, 0 + // state and is not a destruction to report. Ignored delete errors report state + // removal; attempted operations that did not complete count as failed. + deleted, failed, unbound := 0, 0, 0 for _, a := range plan.GetActions() { if a.ActionType != deployplan.Delete || a.IsChildResource() || a.IsStateOnlyDelete() { continue } - if a.Applied { + if a.Unbound { + unbound++ + } else if a.Applied { deleted++ - } else if a.Attempted { + } + if a.Attempted && !a.Applied { failed++ } } @@ -162,6 +165,9 @@ func logDestroySummary(ctx context.Context, b *bundle.Bundle, plan *deployplan.P if failed > 0 { summary += fmt.Sprintf(", %d failed", failed) } + if unbound > 0 { + summary += fmt.Sprintf(", %d removed from state", unbound) + } cmdio.LogString(ctx, summary) } }