@@ -11,24 +11,36 @@ import (
11
11
func TestAccComputeRouterInterface_basic (t * testing.T ) {
12
12
t .Parallel ()
13
13
14
- routerName := fmt .Sprintf ("tf-test-router-%s" , RandString (t , 10 ))
14
+ name := fmt .Sprintf ("tf-test-router-%s" , RandString (t , 10 ))
15
+ context := map [string ]interface {}{
16
+ "name" : name ,
17
+ "region" : "us-central1" ,
18
+ }
19
+ importIdFourPart := fmt .Sprintf ("%s/%s/%s/%s" , GetTestProjectFromEnv (), context ["region" ], context ["name" ], context ["name" ]) // name reused in config
20
+
15
21
VcrTest (t , resource.TestCase {
16
22
PreCheck : func () { AccTestPreCheck (t ) },
17
23
ProtoV5ProviderFactories : ProtoV5ProviderFactories (t ),
18
24
CheckDestroy : testAccCheckComputeRouterInterfaceDestroyProducer (t ),
19
25
Steps : []resource.TestStep {
20
26
{
21
- Config : testAccComputeRouterInterfaceBasic (routerName ),
27
+ Config : testAccComputeRouterInterfaceBasic (context ),
22
28
Check : testAccCheckComputeRouterInterfaceExists (
23
29
t , "google_compute_router_interface.foobar" ),
24
30
},
31
+ {
32
+ ResourceName : "google_compute_router_interface.foobar" ,
33
+ ImportState : true , // Will use the 3 part {{region}}/{{router}}/{{name}} import id by default as it's the id in state
34
+ ImportStateVerify : true ,
35
+ },
25
36
{
26
37
ResourceName : "google_compute_router_interface.foobar" ,
27
38
ImportState : true ,
39
+ ImportStateId : importIdFourPart , // Make test step use 4 part {{project}}/{{region}}/{{router}}/{{name}} import id
28
40
ImportStateVerify : true ,
29
41
},
30
42
{
31
- Config : testAccComputeRouterInterfaceKeepRouter (routerName ),
43
+ Config : testAccComputeRouterInterfaceKeepRouter (name ),
32
44
Check : testAccCheckComputeRouterInterfaceDelete (
33
45
t , "google_compute_router_interface.foobar" ),
34
46
},
@@ -227,40 +239,40 @@ func testAccCheckComputeRouterInterfaceExists(t *testing.T, n string) resource.T
227
239
}
228
240
}
229
241
230
- func testAccComputeRouterInterfaceBasic (routerName string ) string {
231
- return fmt . Sprintf (`
242
+ func testAccComputeRouterInterfaceBasic (context map [ string ] interface {} ) string {
243
+ return Nprintf (`
232
244
resource "google_compute_network" "foobar" {
233
- name = "%s -net"
245
+ name = "%{name} -net"
234
246
}
235
247
236
248
resource "google_compute_subnetwork" "foobar" {
237
- name = "%s -subnet"
249
+ name = "%{name} -subnet"
238
250
network = google_compute_network.foobar.self_link
239
251
ip_cidr_range = "10.0.0.0/16"
240
- region = "us-central1 "
252
+ region = "%{region} "
241
253
}
242
254
243
255
resource "google_compute_address" "foobar" {
244
- name = "%s -addr"
256
+ name = "%{name} -addr"
245
257
region = google_compute_subnetwork.foobar.region
246
258
}
247
259
248
260
resource "google_compute_vpn_gateway" "foobar" {
249
- name = "%s -gateway"
261
+ name = "%{name} -gateway"
250
262
network = google_compute_network.foobar.self_link
251
263
region = google_compute_subnetwork.foobar.region
252
264
}
253
265
254
266
resource "google_compute_forwarding_rule" "foobar_esp" {
255
- name = "%s -fr1"
267
+ name = "%{name} -fr1"
256
268
region = google_compute_vpn_gateway.foobar.region
257
269
ip_protocol = "ESP"
258
270
ip_address = google_compute_address.foobar.address
259
271
target = google_compute_vpn_gateway.foobar.self_link
260
272
}
261
273
262
274
resource "google_compute_forwarding_rule" "foobar_udp500" {
263
- name = "%s -fr2"
275
+ name = "%{name} -fr2"
264
276
region = google_compute_forwarding_rule.foobar_esp.region
265
277
ip_protocol = "UDP"
266
278
port_range = "500-500"
@@ -269,7 +281,7 @@ resource "google_compute_forwarding_rule" "foobar_udp500" {
269
281
}
270
282
271
283
resource "google_compute_forwarding_rule" "foobar_udp4500" {
272
- name = "%s -fr3"
284
+ name = "%{name} -fr3"
273
285
region = google_compute_forwarding_rule.foobar_udp500.region
274
286
ip_protocol = "UDP"
275
287
port_range = "4500-4500"
@@ -278,7 +290,7 @@ resource "google_compute_forwarding_rule" "foobar_udp4500" {
278
290
}
279
291
280
292
resource "google_compute_router" "foobar" {
281
- name = "%s "
293
+ name = "%{name} "
282
294
region = google_compute_forwarding_rule.foobar_udp500.region
283
295
network = google_compute_network.foobar.self_link
284
296
bgp {
@@ -287,12 +299,12 @@ resource "google_compute_router" "foobar" {
287
299
}
288
300
289
301
resource "google_compute_router_interface" "foobar" {
290
- name = "%s "
302
+ name = "%{name} "
291
303
router = google_compute_router.foobar.name
292
304
region = google_compute_router.foobar.region
293
305
ip_range = "169.254.3.1/30"
294
306
}
295
- ` , routerName , routerName , routerName , routerName , routerName , routerName , routerName , routerName , routerName )
307
+ ` , context )
296
308
}
297
309
298
310
func testAccComputeRouterInterfaceRedundant (routerName string ) string {
0 commit comments