From f7cecc2fc4517bb07fa8b735536de80d288e1ba0 Mon Sep 17 00:00:00 2001 From: Max Portocarrero CI&T <105444618+maxi-cit@users.noreply.github.com> Date: Wed, 8 May 2024 15:36:49 -0500 Subject: [PATCH] add autoNetworkTier to Router NAT (#9379) --- mmv1/products/compute/RouterNat.yaml | 10 ++ .../resource_compute_router_nat_test.go.erb | 127 ++++++++++++------ 2 files changed, 94 insertions(+), 43 deletions(-) diff --git a/mmv1/products/compute/RouterNat.yaml b/mmv1/products/compute/RouterNat.yaml index f108e041366d..864939964063 100644 --- a/mmv1/products/compute/RouterNat.yaml +++ b/mmv1/products/compute/RouterNat.yaml @@ -448,3 +448,13 @@ properties: - :PUBLIC - :PRIVATE default_value: :PUBLIC + - !ruby/object:Api::Type::Enum + name: 'autoNetworkTier' + description: | + The network tier to use when automatically reserving NAT IP addresses. + Must be one of: PREMIUM, STANDARD. If not specified, then the current + project-level default tier is used. + values: + - :PREMIUM + - :STANDARD + default_from_api: true diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_router_nat_test.go.erb b/mmv1/third_party/terraform/services/compute/resource_compute_router_nat_test.go.erb index aad9ce68aeda..f638bab4861e 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_router_nat_test.go.erb +++ b/mmv1/third_party/terraform/services/compute/resource_compute_router_nat_test.go.erb @@ -470,6 +470,31 @@ func TestAccComputeRouterNat_withEndpointTypes(t *testing.T) { }) } +func TestAccComputeRouterNat_AutoNetworkTier(t *testing.T) { + t.Parallel() + + testId := acctest.RandString(t, 10) + routerName := fmt.Sprintf("tf-test-router-private-nat-%s", testId) + hubName := fmt.Sprintf("%s-hub", routerName) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRouterNatWitAutoNetworkTier(routerName, hubName), + }, + { + // implicitly full ImportStateId + ResourceName: "google_compute_router_nat.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + <% unless version == 'ga' -%> func TestAccComputeRouterNat_withPrivateNat(t *testing.T) { t.Parallel() @@ -1673,45 +1698,6 @@ resource "google_compute_router_nat" "foobar" { `, routerName, routerName, routerName, routerName) } -<% unless version == "ga" -%> -func testAccComputeRouterNatPrivateType(routerName string) string { - return fmt.Sprintf(` -resource "google_compute_network" "foobar" { - name = "%s-net" - auto_create_subnetworks = false -} - -resource "google_compute_subnetwork" "foobar" { - name = "%s-subnet" - network = google_compute_network.foobar.self_link - ip_cidr_range = "10.0.0.0/16" - region = "us-central1" - purpose = "PRIVATE_NAT" -} - -resource "google_compute_router" "foobar" { - name = "%s" - region = google_compute_subnetwork.foobar.region - network = google_compute_network.foobar.self_link -} - -resource "google_compute_router_nat" "foobar" { - name = "%s" - router = google_compute_router.foobar.name - region = google_compute_router.foobar.region - source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" - type = "PRIVATE" - enable_dynamic_port_allocation = false - enable_endpoint_independent_mapping = false - min_ports_per_vm = 32 - subnetwork { - name = google_compute_subnetwork.foobar.id - source_ip_ranges_to_nat = ["ALL_IP_RANGES"] - } -} -`, routerName, routerName, routerName, routerName) -} - func testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks(routerName, hubName string) string { return fmt.Sprintf(` resource "google_compute_network" "foobar" { @@ -1780,6 +1766,45 @@ resource "google_compute_router" "foobar" { `, routerName, routerName, routerName, routerName, routerName, hubName, routerName, routerName) } +<% unless version == "ga" -%> +func testAccComputeRouterNatPrivateType(routerName string) string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "%s-net" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "foobar" { + name = "%s-subnet" + network = google_compute_network.foobar.self_link + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" + purpose = "PRIVATE_NAT" +} + +resource "google_compute_router" "foobar" { + name = "%s" + region = google_compute_subnetwork.foobar.region + network = google_compute_network.foobar.self_link +} + +resource "google_compute_router_nat" "foobar" { + name = "%s" + router = google_compute_router.foobar.name + region = google_compute_router.foobar.region + source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" + type = "PRIVATE" + enable_dynamic_port_allocation = false + enable_endpoint_independent_mapping = false + min_ports_per_vm = 32 + subnetwork { + name = google_compute_subnetwork.foobar.id + source_ip_ranges_to_nat = ["ALL_IP_RANGES"] + } +} +`, routerName, routerName, routerName, routerName) +} + func testAccComputeRouterNatRulesBasic_privateNatOmitRules(routerName, hubName string) string { return fmt.Sprintf(` %s @@ -1789,7 +1814,7 @@ resource "google_compute_router_nat" "foobar" { router = google_compute_router.foobar.name region = google_compute_router.foobar.region source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" - type = "PRIVATE" + type = "PRIVATE" enable_dynamic_port_allocation = false enable_endpoint_independent_mapping = false min_ports_per_vm = 32 @@ -1810,7 +1835,7 @@ resource "google_compute_router_nat" "foobar" { router = google_compute_router.foobar.name region = google_compute_router.foobar.region source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" - type = "PRIVATE" + type = "PRIVATE" enable_dynamic_port_allocation = false enable_endpoint_independent_mapping = false min_ports_per_vm = 32 @@ -1841,7 +1866,7 @@ resource "google_compute_router_nat" "foobar" { router = google_compute_router.foobar.name region = google_compute_router.foobar.region source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" - type = "PRIVATE" + type = "PRIVATE" enable_dynamic_port_allocation = false enable_endpoint_independent_mapping = false min_ports_per_vm = 32 @@ -1869,7 +1894,7 @@ resource "google_compute_router_nat" "foobar" { router = google_compute_router.foobar.name region = google_compute_router.foobar.region source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" - type = "PRIVATE" + type = "PRIVATE" enable_dynamic_port_allocation = false enable_endpoint_independent_mapping = false min_ports_per_vm = 32 @@ -1891,3 +1916,19 @@ resource "google_compute_router_nat" "foobar" { } <% end -%> + +func testAccComputeRouterNatWitAutoNetworkTier(routerName, hubName string) string { + return fmt.Sprintf(` +%s + +resource "google_compute_router_nat" "foobar" { + name = "%s" + router = google_compute_router.foobar.name + region = google_compute_router.foobar.region + + source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES" + nat_ip_allocate_option = "AUTO_ONLY" + auto_network_tier = "PREMIUM" +} +`, testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks(routerName, hubName), routerName) +}