Skip to content

Commit

Permalink
feat: add support for enable_dynamic_port_allocation and max_ports_pe…
Browse files Browse the repository at this point in the history
…r_vm
  • Loading branch information
zied-elouaer committed May 16, 2024
1 parent 9af82d3 commit 402a60d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
A [Terraform] module for [Google Cloud Platform (GCP)][gcp].

**_This module supports Terraform version 1
and is compatible with the Terraform Google Provider version 4._** and 5._**
and is compatible with the Terraform Google Provider version 4._** (4.28 and later) and 5._**

This module is part of our Infrastructure as Code (IaC) framework
that enables our users and customers to easily deploy and manage reusable,
Expand Down Expand Up @@ -207,10 +207,23 @@ See [variables.tf] and [examples/] for details and use-cases.

Self-links of NAT IPs. Only valid if `natIpAllocateOption` is set to MANUAL_ONLY.

- [**`enable_dynamic_port_allocation`**](#attr-nats-enable_dynamic_port_allocation): *(Optional `bool`)*<a name="attr-nats-enable_dynamic_port_allocation"></a>

Enable Dynamic Port Allocation.
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.

- [**`min_ports_per_vm`**](#attr-nats-min_ports_per_vm): *(Optional `number`)*<a name="attr-nats-min_ports_per_vm"></a>

Minimum number of ports allocated to a VM from this NAT.

- [**`min_ports_per_vm`**](#attr-nats-min_ports_per_vm): *(Optional `number`)*<a name="attr-nats-min_ports_per_vm"></a>

Maximum number of ports allocated to a VM from this NAT.

- [**`udp_idle_timeout_sec`**](#attr-nats-udp_idle_timeout_sec): *(Optional `number`)*<a name="attr-nats-udp_idle_timeout_sec"></a>

Timeout (in seconds) for UDP connections.
Expand Down
21 changes: 20 additions & 1 deletion README.tfdoc.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ section {
A [Terraform] module for [Google Cloud Platform (GCP)][gcp].
**_This module supports Terraform version 1
and is compatible with the Terraform Google Provider version 4._** and 5._**
and is compatible with the Terraform Google Provider version 4._** (4.28 and later) and 5._**
This module is part of our Infrastructure as Code (IaC) framework
that enables our users and customers to easily deploy and manage reusable,
Expand Down Expand Up @@ -269,13 +269,32 @@ section {
END
}

attribute "enable_dynamic_port_allocation" {
type = bool
description = <<-END
Enable Dynamic Port Allocation.
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.
END
}

attribute "min_ports_per_vm" {
type = number
description = <<-END
Minimum number of ports allocated to a VM from this NAT.
END
}

attribute "min_ports_per_vm" {
type = number
description = <<-END
Maximum number of ports allocated to a VM from this NAT.
END
}

attribute "udp_idle_timeout_sec" {
type = number
default = 30
Expand Down
2 changes: 2 additions & 0 deletions nat.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ resource "google_compute_router_nat" "nat" {

nat_ips = try(each.value.nat_ips, null)

enable_dynamic_port_allocation = try(each.value.enable_dynamic_port_allocation, null)
min_ports_per_vm = try(each.value.min_ports_per_vm, null)
max_ports_per_vm = try(each.value.max_ports_per_vm, null)

udp_idle_timeout_sec = try(each.value.idle_timeout_sec, 30)
icmp_idle_timeout_sec = try(each.value.icmp_idle_timeout_sec, 30)
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 3.50, < 6"
version = ">= 4.28, < 6"
}
}
}

0 comments on commit 402a60d

Please sign in to comment.