Skip to content

Commit

Permalink
Merge pull request #3160 from tpdownes/update_nat
Browse files Browse the repository at this point in the history
Update IP address module within VPC module
  • Loading branch information
tpdownes authored Oct 29, 2024
2 parents 4804319 + c531a15 commit cb721a3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/network/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ No providers.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_cloud_router"></a> [cloud\_router](#module\_cloud\_router) | terraform-google-modules/cloud-router/google | ~> 6.0 |
| <a name="module_nat_ip_addresses"></a> [nat\_ip\_addresses](#module\_nat\_ip\_addresses) | terraform-google-modules/address/google | ~> 3.1 |
| <a name="module_nat_ip_addresses"></a> [nat\_ip\_addresses](#module\_nat\_ip\_addresses) | terraform-google-modules/address/google | ~> 4.1 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-google-modules/network/google | ~> 9.0 |

## Resources
Expand All @@ -196,6 +196,7 @@ No resources.
| <a name="input_firewall_log_config"></a> [firewall\_log\_config](#input\_firewall\_log\_config) | Firewall log configuration for Toolkit firewall rules (var.enable\_iap\_ssh\_ingress and others) | `string` | `"DISABLE_LOGGING"` | no |
| <a name="input_firewall_rules"></a> [firewall\_rules](#input\_firewall\_rules) | List of firewall rules | `any` | `[]` | no |
| <a name="input_ips_per_nat"></a> [ips\_per\_nat](#input\_ips\_per\_nat) | The number of IP addresses to allocate for each regional Cloud NAT (set to 0 to disable NAT) | `number` | `2` | no |
| <a name="input_labels"></a> [labels](#input\_labels) | Labels to add to network resources that support labels. Key-value pairs of strings. | `map(string)` | `{}` | no |
| <a name="input_mtu"></a> [mtu](#input\_mtu) | The network MTU (default: 8896). Recommended values: 0 (use Compute Engine default), 1460 (default outside HPC environments), 1500 (Internet default), or 8896 (for Jumbo packets). Allowed are all values in the range 1300 to 8896, inclusively. | `number` | `8896` | no |
| <a name="input_network_address_range"></a> [network\_address\_range](#input\_network\_address\_range) | IP address range (CIDR) for global network | `string` | `"10.0.0.0/9"` | no |
| <a name="input_network_description"></a> [network\_description](#input\_network\_description) | An optional description of this resource (changes will trigger resource destroy/create) | `string` | `""` | no |
Expand Down
8 changes: 7 additions & 1 deletion modules/network/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* limitations under the License.
*/

locals {
# This label allows for billing report tracking based on module.
labels = merge(var.labels, { ghpc_module = "vpc", ghpc_role = "network" })
}

locals {
autoname = replace(var.deployment_name, "_", "-")
network_name = var.network_name == null ? "${local.autoname}-net" : var.network_name
Expand Down Expand Up @@ -175,7 +180,7 @@ module "vpc" {
# https://github.com/terraform-google-modules/terraform-google-address/blob/v3.1.1/outputs.tf
module "nat_ip_addresses" {
source = "terraform-google-modules/address/google"
version = "~> 3.1"
version = "~> 4.1"

for_each = toset(local.regions)

Expand All @@ -184,6 +189,7 @@ module "nat_ip_addresses" {
# an external, regional (not global) IP address is suited for a regional NAT
address_type = "EXTERNAL"
global = false
labels = local.labels
names = [for idx in range(var.ips_per_nat) : "${local.network_name}-nat-ips-${each.value}-${idx}"]
}

Expand Down
7 changes: 7 additions & 0 deletions modules/network/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ variable "project_id" {
type = string
}

variable "labels" {
description = "Labels to add to network resources that support labels. Key-value pairs of strings."
type = map(string)
default = {}
nullable = false
}

variable "network_name" {
description = "The name of the network to be created (if unsupplied, will default to \"{deployment_name}-net\")"
type = string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ deployment_groups:
deployment_name: ((var.deployment_name))
enable_iap_rdp_ingress: true
enable_iap_winrm_ingress: true
labels: ((var.labels))
project_id: ((var.project_id))
region: ((var.region))
- source: modules/file-system/filestore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module "network0" {
deployment_name = var.deployment_name
enable_iap_rdp_ingress = true
enable_iap_winrm_ingress = true
labels = var.labels
project_id = var.project_id
region = var.region
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ deployment_groups:
sensitive: true
settings:
deployment_name: ((var.deployment_name))
labels: ((var.labels))
project_id: ((var.project_id))
region: ((var.region))
- group: one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ terraform {
module "network0" {
source = "./modules/embedded/modules/network/vpc"
deployment_name = var.deployment_name
labels = var.labels
project_id = var.project_id
region = var.region
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ deployment_groups:
id: network
settings:
deployment_name: ((var.deployment_name))
labels: ((var.labels))
project_id: ((var.project_id))
region: ((var.region))
- source: modules/file-system/filestore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
module "network" {
source = "./modules/embedded/modules/network/vpc"
deployment_name = var.deployment_name
labels = var.labels
project_id = var.project_id
region = var.region
}
Expand Down

0 comments on commit cb721a3

Please sign in to comment.