Skip to content

Recreate catalog entities deleted outside Terraform - #127

Merged
ryanduffin merged 1 commit into
rduffin/static-analysis-empty-blockfrom
rduffin/recreate-deleted-catalog-entity
Oct 6, 2026
Merged

ryanduffin merged 1 commit into
rduffin/static-analysis-empty-blockfrom
rduffin/recreate-deleted-catalog-entity

Conversation

@ryanduffin

@ryanduffin ryanduffin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

When a cortex_catalog_entity is deleted outside Terraform, the plan now creates it again instead of failing with "not found".

Claude Details

Summary

  • When an entity was deleted in the UI or through the API, Read returned the API's 404 as an error. Every plan that included the resource failed until someone recreated the entity by hand. terraform destroy failed in the same way.

Changes

  • Read calls RemoveResource when the descriptor read returns cortex.ApiErrorNotFound, so Terraform plans a create. cortex_catalog_entity_openapi and cortex_integration_configuration already do this.
  • Read also adds a warning that names the entity. The API answers 404 for an entity that the token cannot see too (entity visibility permissions, or team entities when the account does not allow them in the catalog API), and the response does not tell these cases apart. In those cases, the apply sends the configured descriptor and then fails on the read after the write, as before.
  • Other read errors still fail the plan and keep the entity in state. The error now names the entity instead of the scaffold text "Unable to read example".
  • The catalog fake can delete an entity or fail reads, and it answers unexpected requests with 500, so that a wrong route in a test is not read as a deleted entity.
  • CHANGELOG entry.

Not in this PR

  • Other resources (for example departments and scorecards) probably have the same gap.
  • Delete still fails on a 404. Normal flows do not reach it, because the refresh before a destroy removes a missing entity first.

Test plan

  • go test ./...: all packages pass.
    • TestUnitCatalogEntity_DeletedOutsideTerraform: the fake deletes the entity between two steps; the second plan must be a create, and the fake must store the entity again.
    • TestUnitCatalogEntity_DestroyAfterDeletedOutsideTerraform: destroy succeeds after an outside delete.
    • TestUnitCatalogEntity_ImportMissingEntity: import of a missing entity fails with Terraform's "Cannot import non-existent remote object".
    • TestUnitCatalogEntity_ReadErrorKeepsState: a 500 fails the plan with an error that names the entity, and a later plan is empty.
    • Mutation check: without the 404 branch, the first three tests fail.
  • gofmt -l, go vet ./..., and golangci-lint run (v2.14.0): clean.
  • make testacc: not run locally. CI runs it.

🤖 Generated with Claude Code

@ryanduffin
ryanduffin added this pull request to stack #128 October 6, 2026 15:30
@ryanduffin
ryanduffin force-pushed the rduffin/recreate-deleted-catalog-entity branch from 2d7ccb8 to 39b1364 Compare October 6, 2026 18:47
When an entity managed by cortex_catalog_entity was deleted in the UI
or through the API, Read returned the "not found" error, so every plan
that included the resource failed until someone recreated the entity
by hand.

Read now removes the resource from state when the API answers 404, so
the plan creates the entity again. This is the same handling as
cortex_catalog_entity_openapi and cortex_integration_configuration.
The API also answers 404 for an entity that the token cannot see, so
Read adds a warning that names the entity. Other read errors still fail
the plan and keep the entity in state, and the error now names the
entity.

A destroy after an outside delete now succeeds, and an import of a
missing entity fails with Terraform's "Cannot import non-existent
remote object".

The catalog fake answers unexpected requests with 500, so that a wrong
route in a test is not read as a deleted entity.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ryanduffin
ryanduffin force-pushed the rduffin/recreate-deleted-catalog-entity branch from 39b1364 to 3314b32 Compare October 6, 2026 19:26
@ryanduffin
ryanduffin marked this pull request as ready for review October 6, 2026 20:24
@ryanduffin
ryanduffin requested a review from gvillenave October 6, 2026 20:25
@ryanduffin
ryanduffin merged commit bf6e454 into main Oct 6, 2026
10 checks passed
@ryanduffin
ryanduffin deleted the rduffin/recreate-deleted-catalog-entity branch October 6, 2026 20:43
Sign up for free to 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.

2 participants