Skip to content

[datadog_software_catalog] Fix software_catalog resource to handle empty API responses for deleted entities#3371

Merged
dd-mergequeue[bot] merged 1 commit intomasterfrom
kruthi.vuppala/fix-get-entities
Dec 18, 2025
Merged

[datadog_software_catalog] Fix software_catalog resource to handle empty API responses for deleted entities#3371
dd-mergequeue[bot] merged 1 commit intomasterfrom
kruthi.vuppala/fix-get-entities

Conversation

@KruthiVuppala
Copy link
Copy Markdown
Contributor

@KruthiVuppala KruthiVuppala commented Dec 16, 2025

Summary

This PR fixes the datadog_software_catalog resource to correctly handle the case when an entity no longer exists in the Software Catalog API.
Fixes #3230

Problem

The Software Catalog API endpoint GET /api/v2/catalog/entity?filter[ref]=<id> is a filtered collection endpoint that returns:

  • 200 OK with entities in the included array when entities match the filter
  • 200 OK with an empty included array when no entities match the filter

This is correct REST semantics for filtered collection endpoints (as opposed to direct resource lookups which return 404).

However, the Terraform provider was incorrectly:

  1. Expecting a 404 response when an entity doesn't exist
  2. Treating empty results as an error instead of detecting drift

This caused issues when:

  • An entity was deleted outside of Terraform (drift detection failed)
  • Running terraform refresh or terraform plan after external deletion

Changes

resource_datadog_software_catalog.go

  • Removed incorrect 404 handling (API doesn't return 404 for filtered queries)
  • Added proper handling for empty included array → removes resource from Terraform state (drift detection)
  • Fixed missing return statement after unmarshalling error
  • Improved error message from "no entity is found" to "unexpected response format" for actual malformed responses

resource_datadog_software_catalog_test.go

  • Updated checkCatalogEntityExists to verify entity exists by checking response body (not just HTTP status)
  • Updated testAccCheckDatadogCatalogEntityDestroy to check for empty included array instead of 404 status
  • Added encoding/json import for response parsing

Testing

  • Ran existing acceptance tests
  • Manually tested drift detection by deleting an entity via API and running terraform plan

Related

This follows proper REST API semantics where:

  • GET /entities?filter=xyz → 200 with empty array (collection exists, filter yields nothing)
  • GET /entities/{id} → 404 if resource doesn't exist

@KruthiVuppala KruthiVuppala requested review from a team as code owners December 16, 2025 21:27
@fpighi fpighi changed the title Fix software_catalog resource to handle empty API responses for deleted entities [datadog_software_catalog] Fix software_catalog resource to handle empty API responses for deleted entities Dec 17, 2025
@KruthiVuppala
Copy link
Copy Markdown
Contributor Author

/merge

@dd-devflow-routing-codex
Copy link
Copy Markdown

dd-devflow-routing-codex Bot commented Dec 18, 2025

View all feedbacks in Devflow UI.

2025-12-18 18:52:11 UTC ℹ️ Start processing command /merge


2025-12-18 18:52:15 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 29m (p90).


2025-12-18 19:22:45 UTC ℹ️ MergeQueue: This merge request was merged

@dd-mergequeue dd-mergequeue Bot merged commit 21d6cc2 into master Dec 18, 2025
15 of 18 checks passed
@dd-mergequeue dd-mergequeue Bot deleted the kruthi.vuppala/fix-get-entities branch December 18, 2025 19:22
paul-hf pushed a commit that referenced this pull request Dec 19, 2025
Handle entity not exists

Co-authored-by: kruthi.vuppala <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource datadog_software_catalog fails violently when resource has already been deleted from UI

4 participants