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 (`
1
47
resource "google_project" "project" {
2
48
project_id = "tf-test%{random_suffix}"
3
49
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}"
6
52
deletion_policy = "DELETE"
7
53
}
8
54
@@ -114,7 +160,7 @@ resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
114
160
region = "us-west2"
115
161
116
162
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 "
118
164
119
165
project = google_project.project.project_id
120
166
}
@@ -125,7 +171,7 @@ resource "google_compute_subnetwork" "psc_ilb_nat" {
125
171
126
172
network = google_compute_network.psc_ilb_network.id
127
173
purpose = "PRIVATE_SERVICE_CONNECT"
128
- ip_cidr_range = "10.1.0.0/16 "
174
+ ip_cidr_range = "10.0. 1.0/24 "
129
175
130
176
project = google_project.project.project_id
131
177
}
@@ -153,10 +199,50 @@ resource "google_apigee_organization" "apigee_org" {
153
199
]
154
200
}
155
201
156
- resource "google_apigee_endpoint_attachment" "{{$.PrimaryResourceId}} " {
202
+ resource "google_apigee_endpoint_attachment" "apigee_endpoint_attachment " {
157
203
org_id = google_apigee_organization.apigee_org.id
158
204
endpoint_attachment_id = "test1"
159
205
location = "us-west2"
160
206
service_attachment = google_compute_service_attachment.psc_ilb_service_attachment.id
161
207
}
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
+ }
162
227
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