@@ -417,6 +417,31 @@ func TestAccComputeRouterNat_withEndpointTypes(t *testing.T) {
417
417
})
418
418
}
419
419
420
+ func TestAccComputeRouterNat_AutoNetworkTier (t * testing.T ) {
421
+ t .Parallel ()
422
+
423
+ testId := acctest .RandString (t , 10 )
424
+ routerName := fmt .Sprintf ("tf-test-router-private-nat-%s" , testId )
425
+ hubName := fmt .Sprintf ("%s-hub" , routerName )
426
+
427
+ acctest .VcrTest (t , resource.TestCase {
428
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
429
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
430
+ CheckDestroy : testAccCheckComputeRouterNatDestroyProducer (t ),
431
+ Steps : []resource.TestStep {
432
+ {
433
+ Config : testAccComputeRouterNatWitAutoNetworkTier (routerName , hubName ),
434
+ },
435
+ {
436
+ // implicitly full ImportStateId
437
+ ResourceName : "google_compute_router_nat.foobar" ,
438
+ ImportState : true ,
439
+ ImportStateVerify : true ,
440
+ },
441
+ },
442
+ })
443
+ }
444
+
420
445
func testAccCheckComputeRouterNatDestroyProducer (t * testing.T ) func (s * terraform.State ) error {
421
446
return func (s * terraform.State ) error {
422
447
config := acctest .GoogleProviderConfig (t )
@@ -1303,3 +1328,87 @@ resource "google_compute_router_nat" "foobar" {
1303
1328
}
1304
1329
` , routerName , routerName , routerName , routerName )
1305
1330
}
1331
+
1332
+ func testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks (routerName , hubName string ) string {
1333
+ return fmt .Sprintf (`
1334
+ resource "google_compute_network" "foobar" {
1335
+ name = "%s-net"
1336
+ auto_create_subnetworks = "false"
1337
+ }
1338
+
1339
+ resource "google_compute_subnetwork" "subnet1" {
1340
+ name = "%s-subnet1"
1341
+ network = google_compute_network.foobar.self_link
1342
+ ip_cidr_range = "10.0.0.0/16"
1343
+ region = "us-central1"
1344
+ purpose = "PRIVATE_NAT"
1345
+ }
1346
+
1347
+ resource "google_compute_subnetwork" "subnet2" {
1348
+ name = "%s-subnet2"
1349
+ network = google_compute_network.foobar.self_link
1350
+ ip_cidr_range = "10.10.1.0/24"
1351
+ region = "us-central1"
1352
+ purpose = "PRIVATE_NAT"
1353
+ }
1354
+
1355
+ resource "google_compute_subnetwork" "subnet3" {
1356
+ name = "%s-subnet3"
1357
+ network = google_compute_network.foobar.self_link
1358
+ ip_cidr_range = "10.158.1.0/24"
1359
+ region = "us-central1"
1360
+ purpose = "PRIVATE_NAT"
1361
+ }
1362
+
1363
+ resource "google_compute_subnetwork" "subnet4" {
1364
+ name = "%s-subnet4"
1365
+ network = google_compute_network.foobar.self_link
1366
+ ip_cidr_range = "10.168.1.0/24"
1367
+ region = "us-central1"
1368
+ purpose = "PRIVATE_NAT"
1369
+ }
1370
+
1371
+ resource "google_network_connectivity_hub" "foobar" {
1372
+ name = "%s"
1373
+ description = "vpc hub for inter vpc nat"
1374
+ }
1375
+
1376
+ resource "google_network_connectivity_spoke" "primary" {
1377
+ name = "%s-spoke"
1378
+ location = "global"
1379
+ description = "vpc spoke for inter vpc nat"
1380
+ hub = google_network_connectivity_hub.foobar.id
1381
+ linked_vpc_network {
1382
+ exclude_export_ranges = [
1383
+ "10.10.0.0/16"
1384
+ ]
1385
+ uri = google_compute_network.foobar.self_link
1386
+ }
1387
+ }
1388
+
1389
+ resource "google_compute_router" "foobar" {
1390
+ name = "%s"
1391
+ region = google_compute_subnetwork.subnet1.region
1392
+ network = google_compute_network.foobar.self_link
1393
+ depends_on = [
1394
+ google_network_connectivity_spoke.primary
1395
+ ]
1396
+ }
1397
+ ` , routerName , routerName , routerName , routerName , routerName , hubName , routerName , routerName )
1398
+ }
1399
+
1400
+ func testAccComputeRouterNatWitAutoNetworkTier (routerName , hubName string ) string {
1401
+ return fmt .Sprintf (`
1402
+ %s
1403
+
1404
+ resource "google_compute_router_nat" "foobar" {
1405
+ name = "%s"
1406
+ router = google_compute_router.foobar.name
1407
+ region = google_compute_router.foobar.region
1408
+
1409
+ source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
1410
+ nat_ip_allocate_option = "AUTO_ONLY"
1411
+ auto_network_tier = "PREMIUM"
1412
+ }
1413
+ ` , testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks (routerName , hubName ), routerName )
1414
+ }
0 commit comments