Skip to content

direct: handle remotely deleted resources - #3710

Merged
denik merged 2 commits into
mainfrom
denik/delete-deleted
Oct 2, 2025
Merged

direct: handle remotely deleted resources#3710
denik merged 2 commits into
mainfrom
denik/delete-deleted

Conversation

@denik

@denikdenik commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Changes

  • When planning resource deletion, skip resource that were already deleted.
  • When DoDelete returns 'resource not found', consider it a success and continue.
  • Fix metadata computation not to error on resources that are deleted.
  • Combine CalculatePlanFor{Deploy,Destroy} into one function.

Why

Better plan, matches terraform.

Tests

New acceptance test that remotely delete a job and test deploy/destroy.

@denik
deniktemporarily deployed to test-trigger-is October 2, 2025 14:58 — with GitHub Actions Inactive
@denikdenik changed the title direct: better plan for remotely deleted resourcesdirect: handle remotely deleted resourcesOct 2, 2025
@denik
denik enabled auto-merge October 2, 2025 15:11
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator

Run: 18196918593

Env✅​pass🙈​skip
✅​aws linux320537
✅​aws windows321536
✅​aws-ucws linux436433
✅​aws-ucws windows437432
✅​azure linux320536
✅​azure windows321535
✅​azure-ucws linux436432
✅​azure-ucws windows437431
✅​gcp linux319538
✅​gcp windows320537

// root
l := b.Config.GetLocation("resources.jobs." + name)
if l.File == "" {
// b.Config.Resources.Jobs may include a job that only exists in state but not in config

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.

Why is this possible and why only for jobs?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I think that's because we populate ID and URL for all resources (for summary)? I don't have a repro, this maybe triggered under specific conditions, but I've seen this particular error before.

It's only happening for jobs because this code is only run for jobs but other resources would behave the same.

@denik
denik added this pull request to the merge queueOct 2, 2025
Merged via the queue into main with commit 2bddd05Oct 2, 2025
13 checks passed
@denik
denik deleted the denik/delete-deleted branch October 2, 2025 15:42
denik added a commit that referenced this pull request May 20, 2026
## Changes
- When planning resource deletion, skip resource that were already
deleted.
- When DoDelete returns 'resource not found', consider it a success and
continue.
- Fix metadata computation not to error on resources that are deleted.
- Combine CalculatePlanFor{Deploy,Destroy} into one function.
## Why
Better plan, matches terraform.
## Tests
New acceptance test that remotely delete a job and test deploy/destroy.
afberg pushed a commit to afberg/cli that referenced this pull request Jul 3, 2026
…emoved from config (databricks#5496)
## Why
Found during a full-repo review of the CLI. With the direct engine, a
resource that was deleted remotely and then removed from the bundle
config could never leave the deployment state. The plan dropped its
Delete entry, so the state cleanup never ran and the stale entry came
back on every deploy. For pipelines and dashboards the same scenario was
worse: the deploy hard-failed in metadata computation with "failed to
compute relative path", and since the state never got cleaned, every
following deploy failed the same way.
## Changes
Before, deploying after a resource was deleted remotely and removed from
config either left a stale state entry forever (jobs) or failed the
deploy outright (pipelines, dashboards); now the deploy plans a delete
for the stale entry, cleans it from state, and completes.
- `bundle/direct/bundle_plan.go`: when planning a Delete and the remote
read reports the resource is gone, keep the Delete entry instead of
removing it from the plan. `Delete()` already tolerates missing
resources and removes the entry from state when applied.
- `bundle/deployplan/plan.go`: remove `RemoveEntry`, whose only caller
was the code path above.
- `bundle/deploy/metadata/compute.go`: add the missing `l.File == ""`
guard to the pipelines and dashboards loops, matching the guard the jobs
loop received in databricks#3710. State-only resources have no config location,
and `filepath.Rel` errors on an empty path.
A side effect visible in test output: `bundle destroy` with the direct
engine now lists a remotely deleted resource under "The following
resources will be deleted", since its state entry is now explicitly
cleaned instead of silently dropped.
## Test plan
- [x] New acceptance test
`acceptance/bundle/resources/jobs/remote_delete/removed_from_config`
covering deploy, remote delete of a job and a pipeline, config removal,
deploy twice, and summary, for both engines. With the direct engine the
first deploy cleans the stale entries and the second deploy and summary
are clean. The terraform variant also exercises the new metadata guard,
since terraform keeps the gone resources in its state.
- [x] New unit test `TestComputeMetadataMutatorStateOnlyResources`
verifying state-only jobs, pipelines, and dashboards are skipped without
error.
- [x] Unit tests for `bundle/direct`, `bundle/deployplan`, and
`bundle/deploy/metadata`.
- [x] Existing acceptance tests around the changed paths
(`jobs/remote_delete`, `volumes/remote-delete`,
`volumes/remote-change-name`, `vector_search_indexes/drift`,
`permissions`, `deployment/bind`, `deployment/unbind`, `bundle/destroy`,
`bundle/generate`, `bundle/invariant`, `clusters`, `quality_monitors`,
`registered_models`, synced tables). Only `jobs/remote_delete/destroy`
changed output (direct destroy now lists the gone job) and was
regenerated with `-update`.
- [x] `./task fmt-q`, `./task lint-q`, `./task checks`.
This pull request and its description were written by Isaac.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@denik@eng-dev-ecosystem-bot@andrewnester