Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmv1/products/apigee/Envgroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
base_url: '{{op_id}}'
result:
resource_inside_response: true
read_error_transform: 'transformApigeeNotFoundError'
custom_code:
custom_import: 'templates/terraform/custom_import/apigee_environment_group.go.tmpl'
exclude_sweeper: true
Expand All @@ -48,7 +49,7 @@
vars:
envgroup_name: 'my-envgroup'
exclude_test: true
# This is a more verbose version of the above that creates all

Check warning on line 52 in mmv1/products/apigee/Envgroup.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

52:7 [comments-indentation] comment not indented like content
# the resources needed for the acceptance test.
- name: 'apigee_environment_group_basic_test'
primary_resource_id: 'apigee_environment_group'
Expand All @@ -56,7 +57,7 @@
org_id: 'ORG_ID'
billing_account: 'BILLING_ACCT'
exclude_docs: true
# Resource creation race

Check warning on line 60 in mmv1/products/apigee/Envgroup.yaml

View workflow job for this annotation

GitHub Actions / lint-yaml

60:7 [comments-indentation] comment not indented like content
skip_vcr: true
external_providers: ["time"]
parameters:
Expand Down
1 change: 1 addition & 0 deletions mmv1/products/apigee/Organization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async:
resource_inside_response: true
sweeper:
identifier_field: "organization"
read_error_transform: 'transformApigeeNotFoundError'
custom_code:
encoder: 'templates/terraform/encoders/apigee_organization.go.tmpl'
custom_import: 'templates/terraform/custom_import/apigee_organization.go.tmpl'
Expand Down
21 changes: 21 additions & 0 deletions mmv1/third_party/terraform/services/apigee/apigee_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package apigee
import (
"encoding/json"
"fmt"
"strings"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
Expand All @@ -13,6 +16,24 @@ import (
"time"
)

// transformApigeeNotFoundError converts a 403 that Apigee returns when a
// resource does not exist (instead of 404) into a 404 error, so that
// HandleNotFoundError can correctly remove the resource from state.
//
// Apigee deliberately returns 403 to avoid leaking information about whether a
// resource exists, but for Terraform reads we must treat "may not exist" as
// "not found".
func transformApigeeNotFoundError(err error) error {
if gErr, ok := errwrap.GetType(err, &googleapi.Error{}).(*googleapi.Error); ok {
if gErr.Code == 403 && strings.Contains(gErr.Message, "or it may not exist") {
log.Printf("[DEBUG] Treating Apigee 403 as 404 (resource may not exist)")
gErr.Code = 404
}
return gErr
}
return err
}

func resourceApigeeNatAddressActivate(config *transport_tpg.Config, d *schema.ResourceData, billingProject string, userAgent string) error {
// 1. check prepare for activation
name := d.Get("name").(string)
Expand Down
Loading