From 679680420d7474b968b67be4085c8718068109db Mon Sep 17 00:00:00 2001 From: Nikhil Makhijani <72851103+nikhilmakhijani@users.noreply.github.com> Date: Fri, 23 Jun 2023 17:27:21 +0000 Subject: [PATCH 1/2] fix: adding support for max ports per vm --- README.md | 1 + main.tf | 1 + variables.tf | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index b889591..657c10d 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Then perform the following commands on the root folder: | icmp\_idle\_timeout\_sec | Timeout (in seconds) for ICMP connections. Defaults to 30s if not set. Changing this forces a new NAT to be created. | `string` | `"30"` | no | | log\_config\_enable | Indicates whether or not to export logs | `bool` | `false` | no | | log\_config\_filter | Specifies the desired filtering of logs on this NAT. Valid values are: "ERRORS\_ONLY", "TRANSLATIONS\_ONLY", "ALL" | `string` | `"ALL"` | no | +| max\_ports\_per\_vm | Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled. | `string` | `null` | no | | min\_ports\_per\_vm | Minimum number of ports allocated to a VM from this NAT config. Defaults to 64 if not set. Changing this forces a new NAT to be created. | `string` | `"64"` | no | | name | Defaults to 'cloud-nat-RANDOM\_SUFFIX'. Changing this forces a new NAT to be created. | `string` | `""` | no | | nat\_ips | List of self\_links of external IPs. Changing this forces a new NAT to be created. Value of `nat_ip_allocate_option` is inferred based on nat\_ips. If present set to MANUAL\_ONLY, otherwise AUTO\_ONLY. | `list(string)` | `[]` | no | diff --git a/main.tf b/main.tf index 58bf41a..5d5d414 100644 --- a/main.tf +++ b/main.tf @@ -50,6 +50,7 @@ resource "google_compute_router_nat" "main" { nat_ips = var.nat_ips source_subnetwork_ip_ranges_to_nat = var.source_subnetwork_ip_ranges_to_nat min_ports_per_vm = var.min_ports_per_vm + max_ports_per_vm = var.max_ports_per_vm udp_idle_timeout_sec = var.udp_idle_timeout_sec icmp_idle_timeout_sec = var.icmp_idle_timeout_sec tcp_established_idle_timeout_sec = var.tcp_established_idle_timeout_sec diff --git a/variables.tf b/variables.tf index b4f8ffe..a72f902 100644 --- a/variables.tf +++ b/variables.tf @@ -36,6 +36,12 @@ variable "min_ports_per_vm" { default = "64" } +variable "max_ports_per_vm" { + type = string + description = "Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled." + default = null +} + variable "name" { type = string description = "Defaults to 'cloud-nat-RANDOM_SUFFIX'. Changing this forces a new NAT to be created." From 943c8acd302c51afe727cc38256754419e732d1a Mon Sep 17 00:00:00 2001 From: Nikhil Makhijani <72851103+nikhilmakhijani@users.noreply.github.com> Date: Sun, 25 Jun 2023 04:53:24 +0000 Subject: [PATCH 2/2] fix: making max ports per vm conditonal --- README.md | 2 +- main.tf | 2 +- variables.tf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 657c10d..64fe045 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Then perform the following commands on the root folder: | icmp\_idle\_timeout\_sec | Timeout (in seconds) for ICMP connections. Defaults to 30s if not set. Changing this forces a new NAT to be created. | `string` | `"30"` | no | | log\_config\_enable | Indicates whether or not to export logs | `bool` | `false` | no | | log\_config\_filter | Specifies the desired filtering of logs on this NAT. Valid values are: "ERRORS\_ONLY", "TRANSLATIONS\_ONLY", "ALL" | `string` | `"ALL"` | no | -| max\_ports\_per\_vm | Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled. | `string` | `null` | no | +| max\_ports\_per\_vm | Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled.This will be ignored if enable\_dynamic\_port\_allocation is set to false. | `string` | `null` | no | | min\_ports\_per\_vm | Minimum number of ports allocated to a VM from this NAT config. Defaults to 64 if not set. Changing this forces a new NAT to be created. | `string` | `"64"` | no | | name | Defaults to 'cloud-nat-RANDOM\_SUFFIX'. Changing this forces a new NAT to be created. | `string` | `""` | no | | nat\_ips | List of self\_links of external IPs. Changing this forces a new NAT to be created. Value of `nat_ip_allocate_option` is inferred based on nat\_ips. If present set to MANUAL\_ONLY, otherwise AUTO\_ONLY. | `list(string)` | `[]` | no | diff --git a/main.tf b/main.tf index 5d5d414..b9e961a 100644 --- a/main.tf +++ b/main.tf @@ -50,7 +50,7 @@ resource "google_compute_router_nat" "main" { nat_ips = var.nat_ips source_subnetwork_ip_ranges_to_nat = var.source_subnetwork_ip_ranges_to_nat min_ports_per_vm = var.min_ports_per_vm - max_ports_per_vm = var.max_ports_per_vm + max_ports_per_vm = var.enable_dynamic_port_allocation ? var.max_ports_per_vm : null udp_idle_timeout_sec = var.udp_idle_timeout_sec icmp_idle_timeout_sec = var.icmp_idle_timeout_sec tcp_established_idle_timeout_sec = var.tcp_established_idle_timeout_sec diff --git a/variables.tf b/variables.tf index a72f902..cdef2a4 100644 --- a/variables.tf +++ b/variables.tf @@ -38,7 +38,7 @@ variable "min_ports_per_vm" { variable "max_ports_per_vm" { type = string - description = "Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled." + description = "Maximum number of ports allocated to a VM from this NAT. This field can only be set when enableDynamicPortAllocation is enabled.This will be ignored if enable_dynamic_port_allocation is set to false." default = null }