Skip to content

fix: remove a resource deleted outside Terraform from state - #336

Open
RainerEls wants to merge 3 commits into
devopsarr:mainfrom
RainerEls:fix/read-404-remove-from-state
Open

RainerEls wants to merge 3 commits into
devopsarr:mainfrom
RainerEls:fix/read-404-remove-from-state

Conversation

@RainerEls

Copy link
Copy Markdown
Contributor

Same change as the fix for devopsarr/terraform-provider-prowlarr#291: a resource deleted outside Terraform made every later plan fail with 404 Not Found.

  • helpers.IsNotFound(*http.Response); Read removes the resource from state on a 404 and Delete treats a 404 as already deleted. Other errors fail as before.
  • Applied to all 86 resources that read by ID (the seven config singletons are unchanged; radarr_quality_definition's Delete was already a no-op).
  • TestAcc…ResourceDisappears for one resource of each API family: tag, delay profile, download client, import list, import list exclusion, indexer, metadata, notification, quality profile, remote path mapping, root folder. Not parallel, for the reason given in the prowlarr PR (freed IDs are reused). All eleven fail on main at the refresh plan and pass with the change.

Left out on purpose: custom formats and auto tags (Radarr answers a missing ID there with 500 KeyNotFoundException, not 404). Movies have no disappear test; their Read gets the same change.

Checked against ghcr.io/hotio/radarr:release-6.3.0.10514 (the CI image), Terraform 1.6.6 and 1.4.7: full acceptance suite green, golangci-lint 0 issues.

Read added a client error for any failed request, so an object deleted
in the app (UI or API) failed every later plan with "404 Not Found"
until it was removed with terraform state rm.

On a 404, Read now removes the resource from state, so the next plan
creates it again, and Delete treats a 404 as already deleted. Other
errors still fail as before.

Acceptance tests delete one resource of each API family outside
Terraform and check that the plan recovers and the next apply creates
it again. Custom formats and auto tags are left out: Radarr answers a
missing ID there with 500, not 404.

Refs devopsarr/terraform-provider-prowlarr#291
…s test

The test ran before any parallel test had created the /config root folder, so on a fresh app the create failed with RootFolderExistsValidator. Use rootFolderDSInit as the other import list tests do.
IsNotFound now takes the error: the client returns a *GenericOpenAPIError
whose message is the HTTP status line, so errors.As plus the "404 " prefix
is enough, and the call sites no longer keep the HTTP response.

The unit test runs the real client against an httptest server.
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.

1 participant