Skip to content

Commit

Permalink
compute: support maxPortsPerVm field related to Cloud NAT's enableDyn…
Browse files Browse the repository at this point in the history
…amicPortAllocation

Support for the Dynamic Port Allocation feature (tracked in
terraform-google-modules/terraform-google-cloud-nat#64 and
hashicorp/terraform-provider-google#11052) was initially implemented
in GoogleCloudPlatform#6022, but it lacked support for the maxPortsPerVm field. This
field is crucial to allow the full configuration to work.
  • Loading branch information
dark committed Jun 21, 2022
1 parent 7f33645 commit 0365823
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mmv1/products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13480,12 +13480,19 @@ objects:
name: minPortsPerVm
description: |
Minimum number of ports allocated to a VM from this NAT.
- !ruby/object:Api::Type::Integer
name: maxPortsPerVm
description: |
Maximum number of ports allocated to a VM from this NAT.
This field can only be set when enableDynamicPortAllocation is enabled.
- !ruby/object:Api::Type::Boolean
name: enableDynamicPortAllocation
description: |
Enable Dynamic Port Allocation.
If minPorts is set, minPortsPerVm must be set to a power of two greater than or equal to 32.
If minPortsPerVm is set, minPortsPerVm must be set to a power of two greater than or equal to 32.
If minPortsPerVm is not set, a minimum of 32 ports will be allocated to a VM from this NAT config.
If maxPortsPerVm is set, maxPortsPerVm must be set to a power of two greater than minPortsPerVm.
If maxPortsPerVm is not set, a maximum of 65536 ports will be allocated to a VM from this NAT config.

Mutually exclusive with enableEndpointIndependentMapping.
- !ruby/object:Api::Type::Integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ func TestAccComputeRouterNat_withPortAllocationMethods(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRouterNatWithAllocationMethodWithParameters(routerName, false, true, 256, 8192),
},
{
ResourceName: "google_compute_router_nat.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -660,6 +668,53 @@ resource "google_compute_router_nat" "foobar" {
`, routerName, routerName, routerName, routerName, routerName, enableEndpointIndependentMapping, enableDynamicPortAllocation)
}

func testAccComputeRouterNatWithAllocationMethodWithParameters(routerName string, enableEndpointIndependentMapping, enableDynamicPortAllocation bool, minPortsPerVm, maxPortsPerVm uint32) 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"
}

resource "google_compute_address" "foobar" {
name = "router-nat-%s-addr"
region = google_compute_subnetwork.foobar.region
}

resource "google_compute_router" "foobar" {
name = "%s"
region = google_compute_subnetwork.foobar.region
network = google_compute_network.foobar.self_link
bgp {
asn = 64514
}
}

resource "google_compute_router_nat" "foobar" {
name = "%s"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
nat_ip_allocate_option = "MANUAL_ONLY"
nat_ips = [google_compute_address.foobar.self_link]
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
subnetwork {
name = google_compute_subnetwork.foobar.name
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
}
enable_endpoint_independent_mapping = %t
enable_dynamic_port_allocation = %t
min_ports_per_vm = %d
max_ports_per_vm = %d
}
`, routerName, routerName, routerName, routerName, routerName, enableEndpointIndependentMapping, enableDynamicPortAllocation, minPortsPerVm, maxPortsPerVm)
}

<% unless version == 'ga' -%>
func testAccComputeRouterNatBaseResourcesWithNatIps(routerName string) string {
return fmt.Sprintf(`
Expand Down

0 comments on commit 0365823

Please sign in to comment.