Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/report-removed-from-state.md
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: test-deploy-summary-on-error
18 changes: 17 additions & 1 deletion acceptance/bundle/deploy/summary-on-error/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
7 changes: 7 additions & 0 deletions acceptance/bundle/deploy/summary-on-error/script
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
46 changes: 46 additions & 0 deletions acceptance/bundle/destroy/summary-on-error/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
16 changes: 16 additions & 0 deletions acceptance/bundle/destroy/summary-on-error/script
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@ 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
# job_01 fail while job_03 and job_02 are really deleted. The deferred summary must
# 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}'
4 changes: 2 additions & 2 deletions acceptance/bundle/destroy/summary-on-error/test.toml
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion bundle/deployplan/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 15 additions & 6 deletions bundle/deployplan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -309,6 +317,7 @@ func (p *Plan) GetActions() []Action {
StateOnly: entry.StateOnly,
Attempted: entry.Attempted,
Applied: entry.Applied,
Unbound: entry.Unbound,
})
}

Expand Down
10 changes: 10 additions & 0 deletions bundle/deployplan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
13 changes: 10 additions & 3 deletions bundle/direct/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isManagedByParent sets unbound, so a destroy of a Lakebase branch plus its primary endpoint now prints "Destroy: 2 deleted, 1 removed from state" (postgres_endpoints/replace_existing) even though the parent delete cascade-removes the endpoint, as util.go:9 and that test's script say. Should parent-managed deletes keep counting as deleted rather than reading as left behind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: Parent-managed deletes are reported as "removed from state" although the parent's delete cascade-cleans them, with no name or reason

unbound := isManagedByParent(err) puts every MANAGED_BY_PARENT rejection in the new "removed from state" bucket. isManagedByParent's own doc (bundle/direct/util.go:9-15) says the standalone Delete can be disregarded because the parent's Delete will cascade-clean the resource. On bundle destroy the parent is always in the plan and is deleted in the same run, so these resources are in fact deleted. The new summary says the opposite: any bundle that manages a Lakebase root branch or primary endpoint now prints Destroy: N-1 deleted, 1 removed from state on a fully successful destroy. Seven goldens encode this (postgres_branches/replace_existing, postgres_endpoints/replace_existing, and five postgres_data_apis tests). Before this change the line was N deleted, which was correct for these cases.

The output also contradicts itself. In postgres_data_apis/basic the approval text says the action "will result in the deletion of the following Lakebase branches" and lists resources.postgres_branches.production, and the summary a few lines later reads Destroy: 3 deleted, 1 removed from state.

Unlike the other two unbound branches (permission denied, no history), this branch logs nothing, and destroy prints no per-resource lines (reportApplied is false at bundle/phases/destroy.go:181). The user is told one resource may have been left behind, with no resource name and no reason, and may go looking for an orphaned branch or endpoint that no longer exists. This is the open question from andrewnester on this line; the code at head is unchanged on it.

The case the PR description gives as justification (the parent is kept, or the parent's delete fails) is real, but no test covers it: the only parent-managed scenarios in the suite are destroys where the parent is deleted. rg MANAGED_BY_PARENT acceptance/bundle matches only the postgres_endpoints/replace_existing and postgres_branches/replace_existing scripts, and rg "Removed postgres" acceptance/bundle has no match, so the deploy-path line for a parent-managed resource is not covered either.

Suggested changes (either one):

  • Do not set Unbound for MANAGED_BY_PARENT. This matches how Recreate already treats it (RecreateDeleted = HasDoDelete() && !managedByParent), which counts it as neither deleted nor unbound.
  • Or count a parent-managed rejection as removed from state only when its parent is not deleted in the same apply, and keep counting it as deleted otherwise (the pre-PR result).

If the current behaviour stays, at least log.Warnf the resource key as the other two unbound branches do, and add a test for the parent-kept case.

Evidence:

  • bundle/direct/apply.go:271-273: unbound := isManagedByParent(err) with no log call, while :279-280 and :289-290 pair unbound = true with log.Warnf.
  • acceptance/bundle/resources/postgres_endpoints/replace_existing/out.requests.destroy.json records DELETE .../branches/develop/endpoints/primary, then DELETE .../branches/develop, then DELETE .../projects/test-pg-proj-[UNIQUE_NAME]. libs/testserver/postgres.go:504-514 (branch delete removes its endpoints) and :273-289 (project delete removes branches and endpoints) show the cascade.
  • out.destroy.txt:16 in that test now reads Destroy: 2 deleted, 1 removed from state with no Warn: line above it.
  • acceptance/bundle/resources/postgres_data_apis/basic/output.txt:130-132 lists delete resources.postgres_branches.production under the Lakebase-branch deletion warning, and :140 reads Destroy: 3 deleted, 1 removed from state.

Agreed by 3 reviewer model(s).

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)
Expand All @@ -282,13 +285,17 @@ 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Without deployment history this branch ignores the delete error silently, so the new "Destroy: 2 deleted, 1 removed from state" (destroy/summary-on-error, settled_failure) names no resource and gives no reason. Can it log.Warnf like the permission branch above?

log.Warnf(ctx, "Ignoring error when deleting %s id=%s: %s", d.ResourceKey, oldID, err)
}
}

err = db.DeleteState(ctx, d.ResourceKey, false)
if err != nil {
return fmt.Errorf("deleting state id=%s: %w", oldID, err)
}
entry.Unbound = unbound

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: Unbound deletes still run the delete-wait, and a wait failure counts one resource as both failed and removed from state

entry.Unbound is set before WaitAfterDelete, which still runs even though the delete was rejected and the resource is known to still exist. For resources whose wait polls until the GET fails (vector_search_index, postgres_synced_table), an ignored 403 now means polling until the timeout or cap. A non-capped wait timeout then returns an error. CountApplied and logDestroySummary count that single resource twice: Unbound++ and Failed++. The new unit case wait failure after unbinding still reports state removal ({Unbound: 1, Failed: 1}) locks in that double count.

Polling after an ignored error is not new, but this PR newly ties it to the summary counts. Returning right after entry.Unbound = unbound when unbound is true would remove both the pointless wait and the double count, since the resource was not deleted and there is nothing to wait for.

Evidence:

  • bundle/direct/apply.go:298 sets entry.Unbound before the waitCapped call at :305-311, which returns an error at :310.
  • bundle/direct/dresources/vector_search_index.go:225-233 and postgres_synced_table.go:157-170 poll with Continues("... still exists ...") until GET errors.
  • bundle/deployplan/plan.go:120-127 has if entry.Unbound {c.Unbound++} followed by a separate if entry.Attempted && !entry.Applied {c.Failed++}; bundle/phases/destroy.go:155-162 has the same pattern.
  • bundle/deployplan/plan_test.go:121-124 asserts {Unbound: 1, Failed: 1} for a single entry.

Agreed by 3 reviewer model(s).


// Wait for asynchronous teardown after dropping state. Mirrors Recreate so
// the contract is the same regardless of whether the user triggered
Expand Down
9 changes: 7 additions & 2 deletions bundle/direct/bundle_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"

"github.com/databricks/cli/bundle/config"
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bundle/phases/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading