Skip to content

apigee: handle 403-as-deleted when re-creating Org after out-of-band deletion#16964

Open
xuchenma wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
xuchenma:352445357
Open

apigee: handle 403-as-deleted when re-creating Org after out-of-band deletion#16964
xuchenma wants to merge 2 commits intoGoogleCloudPlatform:mainfrom
xuchenma:352445357

Conversation

@xuchenma
Copy link
Copy Markdown
Contributor

@xuchenma xuchenma commented Apr 5, 2026

Overview

When an Apigee Organization is deleted out-of-band (e.g. via the management API
or console, not through Terraform), the Apigee API returns HTTP 403 with the
message "... (or it may not exist)" instead of 404. This causes Terraform to
surface an opaque permission-denied error rather than proposing re-creation.

Change

Adds a read_error_transform function for google_apigee_organization that
rewrites the ambiguous 403 "(or it may not exist)" response to 404, allowing
HandleNotFoundError to detect the resource as gone and schedule re-creation on
the next apply.

Files changed:

  • mmv1/products/apigee/Organization.yaml — adds read_error_transform: 'transformApigeeOrganizationReadError'
  • mmv1/third_party/terraform/services/apigee/resource_apigee_organization_utils.go — new file defining the transform function

Testing

All acceptance tests pass:

  • TestAccApigeeOrganization_apigeeOrganizationCloudBasicTestExample — PASS (1358s)
  • TestAccApigeeOrganization_apigeeOrganizationCloudBasicDisableVpcPeeringTestExample — PASS (753s)
  • TestAccApigeeOrganization_apigeeOrganizationCloudBasicDataResidencyTestExample — PASS (929s)
  • TestAccApigeeOrganization_update — PASS (1095s)

Fixes: b/352445357

apigee: fixed re-creation of `google_apigee_organization` after out-of-band deletion by correctly handling the 403 "(or it may not exist)" API response as resource-not-found

xuchenma added 2 commits April 4, 2026 01:53
The isEnabled field on TargetServer used the standard IsEmptyValue guard
which treats boolean false as an empty value. This meant setting
is_enabled = false had no effect: the API defaulted to true.

Fix: add send_empty_value: true to the isEnabled field in TargetServer.yaml
so the generated code always includes the field in create and update
requests regardless of its value.

Also adds acceptance test TestAccApigeeTargetServer_apigeeTargetServerIsEnabledFalse
that creates a target server with is_enabled=false, verifies it is
actually disabled, then updates it to true.
…eted

When an Apigee Organization is deleted out-of-band (e.g. via the management
API, not through Terraform), subsequent Terraform plan/apply calls fail with:

  Error 403: Permission denied on resource "organizations/<id>"
  (or it may not exist)

This is because Terraform's state still contains the org, so the Read
function GETs the org -- the Apigee API deliberately returns 403 (not 404)
to avoid leaking existence information.  Terraform does not understand this
as a "resource is gone" signal and surfaces the 403 as a hard error.

Fix: add read_error_transform pointing to transformApigeeOrganizationReadError,
which rewrites the 403 "(or it may not exist)" response to a 404.
HandleNotFoundError then removes the resource from state and the next
terraform plan shows a clean re-creation diff.

Fixes: https://github.com/hashicorp/terraform-provider-google/issues/XXXXX
BUG=352445357
@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 rileykarson April 5, 2026 17:10
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@rileykarson, 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.

2 participants