Skip to content

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
xuchenma:322476813
Open

apigee: treat 403 as not-found in google_apigee_organization and google_apigee_envgroup reads#16963
xuchenma wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
xuchenma:322476813

Conversation

@xuchenma
Copy link
Copy Markdown
Contributor

@xuchenma xuchenma commented Apr 5, 2026

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
```

apigee: fixed `google_apigee_organization` and `google_apigee_envgroup` to handle 403 responses as not-found during read, allowing Terraform to detect and recreate resources deleted outside of Terraform

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
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 5, 2026
@github-actions github-actions bot requested a review from c2thorn April 5, 2026 15:32
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to recreate google_apigee_organization, google_apigee_envgroup after deletion outside Terraform.

2 participants