Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autoNetworkTier to Router NAT #9379

Merged
Merged
10 changes: 10 additions & 0 deletions mmv1/products/compute/RouterNat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}