apigee: treat 403 as not-found in google_apigee_organization and google_apigee_envgroup reads#16963
Open
xuchenma wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Open
apigee: treat 403 as not-found in google_apigee_organization and google_apigee_envgroup reads#16963xuchenma wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
xuchenma wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Conversation
When an Apigee organization or envgroup is deleted outside Terraform, the API returns 403 (instead of 404) to avoid revealing whether a resource exists. Terraform previously treated this as a fatal error, preventing re-creation of the resources. This change adds a transformApigeeNotFoundError helper (following the same pattern as CloudIdentity group memberships) and wires it into the read functions for google_apigee_organization and google_apigee_envgroup via the read_error_transform YAML field. After this fix, Terraform correctly removes the stale resource from state on a 403 'or it may not exist' error, and plans to recreate it. Fixes: hashicorp/terraform-provider-google#17103
|
Googlers: For automatic test runs see go/terraform-auto-test-runs. @c2thorn, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look. You can help make sure that review is quick by doing a self-review and by running impacted tests locally. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Apigee API returns `403` (instead of `404`) when an organization or envgroup does not exist, to prevent resource enumeration. When a resource is deleted outside of Terraform, subsequent `terraform plan` / `terraform apply` calls would receive this 403 and treat it as a fatal authorization error rather than a "not found" signal, preventing Terraform from detecting drift and recreating the resource.
This change adds a `transformApigeeNotFoundError` helper to `apigee_utils.go` (following the same pattern used by `cloud_identity`, `sql`, and other services) and wires it in via `read_error_transform` in `Organization.yaml` and `Envgroup.yaml`.
The transform converts a 403 that contains the Apigee-specific message "or it may not exist" to a 404, which `HandleNotFoundError` then handles gracefully.
Fixes: hashicorp/terraform-provider-google#17103
Tests
The acceptance test for envgroup (`TestAccApigeeEnvgroup_apigeeEnvironmentGroupBasicTestExample`) requires provisioning a full Apigee organization (~30-60 min) and cannot reliably be run locally within CI time limits. The fix follows an established pattern used across the codebase.
Build verified:
```
go build ./google/services/apigee/... # exits 0
```