Skip to content

Commit 15092fc

Browse files
hao-nan-lianoopkverma-google
authored andcommitted
Fix TestAccApigeeEndpointAttachment_apigeeEndpointAttachmentBasicTestExample (GoogleCloudPlatform#12793)
1 parent f687da3 commit 15092fc

File tree

2 files changed

+91
-18
lines changed

2 files changed

+91
-18
lines changed

mmv1/products/apigee/EndpointAttachment.yaml

-13
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ async:
4343
custom_code:
4444
custom_import: 'templates/terraform/custom_import/apigee_endpoint_attachment.go.tmpl'
4545
exclude_sweeper: true
46-
examples:
47-
- name: 'apigee_endpoint_attachment_basic'
48-
exclude_test: true
49-
# This is a more verbose version of the above that creates all
50-
# the resources needed for the acceptance test.
51-
- name: 'apigee_endpoint_attachment_basic_test'
52-
primary_resource_id: 'apigee_endpoint_attachment'
53-
test_env_vars:
54-
org_id: 'ORG_ID'
55-
billing_account: 'BILLING_ACCT'
56-
exclude_docs: true
57-
# Resource creation race
58-
skip_vcr: true
5946
parameters:
6047
- name: 'orgId'
6148
type: String

mmv1/templates/terraform/examples/apigee_endpoint_attachment_basic_test.tf.tmpl renamed to mmv1/third_party/terraform/services/apigee/resource_apigee_endpoint_attachment_test.go

+91-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
1+
package apigee_test
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/terraform"
10+
11+
"github.com/hashicorp/terraform-provider-google/google/acctest"
12+
"github.com/hashicorp/terraform-provider-google/google/envvar"
13+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
14+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
15+
)
16+
17+
func TestAccApigeeEndpointAttachment_apigeeEndpointAttachmentBasicTestExample(t *testing.T) {
18+
acctest.SkipIfVcr(t)
19+
t.Parallel()
20+
21+
context := map[string]interface{}{
22+
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
23+
"org_id": envvar.GetTestOrgFromEnv(t),
24+
"random_suffix": acctest.RandString(t, 10),
25+
}
26+
27+
acctest.VcrTest(t, resource.TestCase{
28+
PreCheck: func() { acctest.AccTestPreCheck(t) },
29+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
30+
CheckDestroy: testAccCheckApigeeEndpointAttachmentDestroyProducer(t),
31+
Steps: []resource.TestStep{
32+
{
33+
Config: testAccApigeeEndpointAttachment_apigeeEndpointAttachmentBasicTestExample(context),
34+
},
35+
{
36+
ResourceName: "google_apigee_endpoint_attachment.apigee_endpoint_attachment",
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
ImportStateVerifyIgnore: []string{"endpoint_attachment_id", "org_id"},
40+
},
41+
},
42+
})
43+
}
44+
45+
func testAccApigeeEndpointAttachment_apigeeEndpointAttachmentBasicTestExample(context map[string]interface{}) string {
46+
return acctest.Nprintf(`
147
resource "google_project" "project" {
248
project_id = "tf-test%{random_suffix}"
349
name = "tf-test%{random_suffix}"
4-
org_id = "{{index $.TestEnvVars "org_id"}}"
5-
billing_account = "{{index $.TestEnvVars "billing_account"}}"
50+
org_id = "%{org_id}"
51+
billing_account = "%{billing_account}"
652
deletion_policy = "DELETE"
753
}
854
@@ -114,7 +160,7 @@ resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
114160
region = "us-west2"
115161
116162
network = google_compute_network.psc_ilb_network.id
117-
ip_cidr_range = "10.0.0.0/16"
163+
ip_cidr_range = "10.0.1.0/24"
118164
119165
project = google_project.project.project_id
120166
}
@@ -125,7 +171,7 @@ resource "google_compute_subnetwork" "psc_ilb_nat" {
125171
126172
network = google_compute_network.psc_ilb_network.id
127173
purpose = "PRIVATE_SERVICE_CONNECT"
128-
ip_cidr_range = "10.1.0.0/16"
174+
ip_cidr_range = "10.0.1.0/24"
129175
130176
project = google_project.project.project_id
131177
}
@@ -153,10 +199,50 @@ resource "google_apigee_organization" "apigee_org" {
153199
]
154200
}
155201
156-
resource "google_apigee_endpoint_attachment" "{{$.PrimaryResourceId}}" {
202+
resource "google_apigee_endpoint_attachment" "apigee_endpoint_attachment" {
157203
org_id = google_apigee_organization.apigee_org.id
158204
endpoint_attachment_id = "test1"
159205
location = "us-west2"
160206
service_attachment = google_compute_service_attachment.psc_ilb_service_attachment.id
161207
}
208+
`, context)
209+
}
210+
211+
func testAccCheckApigeeEndpointAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
212+
return func(s *terraform.State) error {
213+
for name, rs := range s.RootModule().Resources {
214+
if rs.Type != "google_apigee_endpoint_attachment" {
215+
continue
216+
}
217+
if strings.HasPrefix(name, "data.") {
218+
continue
219+
}
220+
221+
config := acctest.GoogleProviderConfig(t)
222+
223+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{ApigeeBasePath}}{{org_id}}/endpointAttachments/{{endpoint_attachment_id}}")
224+
if err != nil {
225+
return err
226+
}
162227

228+
billingProject := ""
229+
230+
if config.BillingProject != "" {
231+
billingProject = config.BillingProject
232+
}
233+
234+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
235+
Config: config,
236+
Method: "GET",
237+
Project: billingProject,
238+
RawURL: url,
239+
UserAgent: config.UserAgent,
240+
})
241+
if err == nil {
242+
return fmt.Errorf("ApigeeEndpointAttachment still exists at %s", url)
243+
}
244+
}
245+
246+
return nil
247+
}
248+
}

0 commit comments

Comments
 (0)