fix: handle 404 gracefully on gitlab_branch_protection delete
What does this MR do and why?
Fixes #6852 (closed).
When GitLab returns 404 Not Found during a terraform destroy of a gitlab_branch_protection resource (e.g. the branch protection was already deleted out-of-band), the provider previously surfaced a hard error and left the resource stuck in Terraform state.
This change adds a 404 check in the Delete handler: if the API returns 404, the provider logs a debug message and returns without error — treating the resource as already gone. This is consistent with the pattern already used in the Read and Update handlers of the same resource.
MR acceptance checklist
- Followed the Contribution guidelines
- Acceptance test added (
TestAccGitlabBranchProtection_deleteOutOfBand) covering the out-of-band deletion scenario - Code follows existing patterns (
api.Is404helper,tflog.Debugfor the warning)
Changes
internal/provider/resource_gitlab_branch_protection.go
In Delete, after calling UnprotectRepositoryBranches, check for a 404 response and return without error if found.
internal/provider/resource_gitlab_branch_protection_test.go
Added TestAccGitlabBranchProtection_deleteOutOfBand which:
- Creates a branch protection via Terraform.
- Deletes it out-of-band via the GitLab API in a
PreConfigfunction. - Runs
Destroy: trueand verifies the destroy completes without error.