Remove the Datadog, Jenkins and Harbor project integrations from state on 404

What does this MR do and why?

gitlab_project_integration_datadog, gitlab_project_integration_jenkins and gitlab_project_integration_harbor failed every plan with Unable to read ... integration: 404 Not Found once their project had been deleted outside of Terraform, and terraform destroy -refresh=false failed the same way on the DELETE. They were the only integration resources on the plugin framework that didn't handle the 404.

This MR makes each of them remove itself from the state on a 404 in Read and treat a 404 in Delete as nothing left to delete, the way the other 18 do. There is one commit per resource, each with its acceptance test, after a first commit that adds the test helper the three tests share:

  1. testutil.DeleteProjectAndWait deletes a project for good and polls it until GitLab answers 404. A DELETE only marks the project for deletion, and the permanent delete that follows runs in the background, so the project stays readable for a few seconds. The project cleanup in CreateProjectWithOptions now calls the shared part instead of keeping its own copy, and does what it did before.
  2. Datadog, 3. Jenkins, 4. Harbor: the fix and a _projectDeletedOutsideTerraform acceptance test, modelled on TestAccGitlabProjectVariable_deletedOutsideTerraform. It creates the integration, deletes its project in PreConfig, and checks with a plan check that the refresh plans to create the integration again. terraform-plugin-testing runs the destroy at the end of a test with -refresh=false, so that destroy covers the Delete change: with only the Read change, the Datadog test fails there with Unable to delete Datadog integration: 404 Not Found.

Each commit builds and passes on its own, one resource at a time, so the branch can also be merged without squashing if that is easier to follow later.

Closes #6905 (closed)

How to verify

unset GITLAB_TOKEN && make testacc-up
unset GITLAB_TOKEN && make testacc RUN=_projectDeletedOutsideTerraform

Each new test fails with the 404 when its resource is left as it is on main, and passes with its commit.

What I ran (GitLab CE 19.4.1, Go 1.26.5)

Each test before the fix of its resource:

--- FAIL: TestAccGitlabProjectIntegrationDataDog_projectDeletedOutsideTerraform
    Step 2/2 error: Error running refresh plan: exit status 1
    Unable to read Datadog integration: 404 Not Found
    Error running post-test destroy, there may be dangling resources: exit status 1
    Unable to delete Datadog integration: 404 Not Found
--- FAIL: TestAccGitlabProjectIntegrationJenkins_projectDeletedOutsideTerraform
    Step 2/2 error: Error running refresh plan: exit status 1
    Unable to read gitlab jenkins integration: 404 Not Found
    Error running post-test destroy, there may be dangling resources: exit status 1
    Unable to delete Jenkins integration: 404 Not Found
--- FAIL: TestAccGitlabProjectIntegrationHarbor_projectDeletedOutsideTerraform
    Step 2/2 error: Error running refresh plan: exit status 1
    Unable to read gitlab harbor integration: 404 Not Found
    Error running post-test destroy, there may be dangling resources: exit status 1
    Unable to delete Harbor integration: 404 Not Found

The Datadog test with the Read change and without the Delete one:

--- FAIL: TestAccGitlabProjectIntegrationDataDog_projectDeletedOutsideTerraform
    Error running post-test destroy, there may be dangling resources: exit status 1
    Unable to delete Datadog integration: 404 Not Found

This branch, with make testacc RUN=_projectDeletedOutsideTerraform:

--- PASS: TestAccGitlabProjectIntegrationHarbor_projectDeletedOutsideTerraform (3.82s)
--- PASS: TestAccGitlabProjectIntegrationDataDog_projectDeletedOutsideTerraform (4.00s)
--- PASS: TestAccGitlabProjectIntegrationJenkins_projectDeletedOutsideTerraform (4.22s)

The existing tests of the three resources (_basic for each, _stateMove for Jenkins and Harbor, _validation for Harbor) and the other TestAccGitlabProjectIntegration* tests pass on this branch (the GitHub ones skip on CE), and so do the Datadog and Jenkins _basic tests on the first commit alone, which run the refactored project cleanup; no test project was left behind on the instance.

With the configuration from the issue, v19.4.1 fails terraform plan on all three integrations once the project is gone. A provider built from this branch (through a dev_overrides block) plans to create the project and the three integrations again, and terraform destroy -refresh=false on the same state completes (Destroy complete! Resources: 4 destroyed.).

Each commit builds and passes gofmt, go vet -tags acceptance, golangci-lint run --build-tags acceptance (0 issues) and go test ./internal/provider/... ./scripts/.... On the last commit, make reviewable finishes cleanly and changes no tracked file, and make lint-tfprovider, lint-examples-tf, lint-examples-sh and lint-custom pass.

gitlab_integration_slack, the one integration still on the SDK, already removes itself from the state on a 404 in Read, and its Delete still fails on one. I left it out to keep this to the three resources the issue is about.

!2417 (merged) removed project and group variables from the state when they are not found, and !3176 (merged) and !3181 (merged) made deleting a branch protection and a group membership ignore a 404.

Merge request reports

Loading
Loading