Skip to content

Conversation

@tomazpu
Copy link
Collaborator

@tomazpu tomazpu commented Nov 13, 2025

Why this PR?

This PR is connected to the GitHub issue #868, where an API, after a successful POST request, returns a 404 on the consequent read operation with the objectId.

As there is a state mismatch, Terraform will fail without an error message.

What has changed?

  1. Removed unused code block
  2. Introduced APIError
  3. Using the APIError and removing the silent failing on a 404 error

How does it do it?

How is it tested?

Manually tested and covered by tests

How does it affect users?

The user should be provided with a better error message. Example below.
│ Error: API Error: <GET> Settings modification only visible for devops
Issue:

@sonarqubecloud
Copy link

}
return diag.FromErr(err)

d.SetId("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have several behavior changes in here. It's not just the 404 shows an error fix.

  1. d.SetId("") and diag.FromErr is now always called, even if the service.Get(ctx, d.Id(), sttngs) before succeeds (the one inside the re-run with confighcl check)
  2. setId is also called if it's a non-404 status code (before it was only for 404). Not sure if this is good or bad. If there is a server outage (e.g., 503), would this mean that the resource is removed from the state file?
  3. If you create a resource via Terraform and then delete it via the API (outside of Terraform), will the next terraform apply produce an error instead of suggesting to create it?

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.

3 participants