From f54b4f88b80823bed4e4bef43c56f11f81d68c80 Mon Sep 17 00:00:00 2001 From: Luca Prete Date: Mon, 23 Oct 2023 17:17:06 +0200 Subject: [PATCH] net-address: allow users to optionally specify address names (#1795) --- modules/net-address/README.md | 14 +++++++------- modules/net-address/main.tf | 10 +++++----- modules/net-address/variables.tf | 8 +++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/net-address/README.md b/modules/net-address/README.md index 9f122352bc..c99ca511ae 100644 --- a/modules/net-address/README.md +++ b/modules/net-address/README.md @@ -106,13 +106,13 @@ module "addresses" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [project_id](variables.tf#L65) | Project where the addresses will be created. | string | ✓ | | -| [external_addresses](variables.tf#L17) | Map of external addresses, keyed by name. | map(object({…})) | | {} | -| [global_addresses](variables.tf#L27) | List of global addresses to create. | list(string) | | [] | -| [internal_addresses](variables.tf#L33) | Map of internal addresses to create, keyed by name. | map(object({…})) | | {} | -| [ipsec_interconnect_addresses](variables.tf#L47) | Map of internal addresses used for HPA VPN over Cloud Interconnect. | map(object({…})) | | {} | -| [psa_addresses](variables.tf#L70) | Map of internal addresses used for Private Service Access. | map(object({…})) | | {} | -| [psc_addresses](variables.tf#L81) | Map of internal addresses used for Private Service Connect. | map(object({…})) | | {} | +| [project_id](variables.tf#L68) | Project where the addresses will be created. | string | ✓ | | +| [external_addresses](variables.tf#L17) | Map of external addresses, keyed by name. | map(object({…})) | | {} | +| [global_addresses](variables.tf#L28) | List of global addresses to create. | list(string) | | [] | +| [internal_addresses](variables.tf#L34) | Map of internal addresses to create, keyed by name. | map(object({…})) | | {} | +| [ipsec_interconnect_addresses](variables.tf#L49) | Map of internal addresses used for HPA VPN over Cloud Interconnect. | map(object({…})) | | {} | +| [psa_addresses](variables.tf#L73) | Map of internal addresses used for Private Service Access. | map(object({…})) | | {} | +| [psc_addresses](variables.tf#L86) | Map of internal addresses used for Private Service Connect. | map(object({…})) | | {} | ## Outputs diff --git a/modules/net-address/main.tf b/modules/net-address/main.tf index b09ba231af..f80cab291c 100644 --- a/modules/net-address/main.tf +++ b/modules/net-address/main.tf @@ -24,7 +24,7 @@ resource "google_compute_address" "external" { provider = google-beta for_each = var.external_addresses project = var.project_id - name = each.key + name = coalesce(each.value.name, each.key) description = each.value.description address_type = "EXTERNAL" region = each.value.region @@ -35,7 +35,7 @@ resource "google_compute_address" "internal" { provider = google-beta for_each = var.internal_addresses project = var.project_id - name = each.key + name = coalesce(each.value.name, each.key) description = each.value.description address_type = "INTERNAL" region = each.value.region @@ -49,7 +49,7 @@ resource "google_compute_address" "internal" { resource "google_compute_global_address" "psc" { for_each = var.psc_addresses project = var.project_id - name = each.key + name = coalesce(each.value.name, each.key) description = each.value.description address = try(each.value.address, null) address_type = "INTERNAL" @@ -61,7 +61,7 @@ resource "google_compute_global_address" "psc" { resource "google_compute_global_address" "psa" { for_each = var.psa_addresses project = var.project_id - name = each.key + name = coalesce(each.value.name, each.key) description = each.value.description address = each.value.address address_type = "INTERNAL" @@ -74,7 +74,7 @@ resource "google_compute_global_address" "psa" { resource "google_compute_address" "ipsec_interconnect" { for_each = var.ipsec_interconnect_addresses project = var.project_id - name = each.key + name = coalesce(each.value.name, each.key) description = each.value.description address = each.value.address address_type = "INTERNAL" diff --git a/modules/net-address/variables.tf b/modules/net-address/variables.tf index ebcfa5b662..9f7c5c70d3 100644 --- a/modules/net-address/variables.tf +++ b/modules/net-address/variables.tf @@ -20,6 +20,7 @@ variable "external_addresses" { region = string description = optional(string, "Terraform managed.") labels = optional(map(string), {}) + name = optional(string) })) default = {} } @@ -38,6 +39,7 @@ variable "internal_addresses" { address = optional(string) description = optional(string, "Terraform managed.") labels = optional(map(string)) + name = optional(string) purpose = optional(string) tier = optional(string) })) @@ -51,6 +53,7 @@ variable "ipsec_interconnect_addresses" { address = string network = string description = optional(string, "Terraform managed.") + name = optional(string) prefix_length = number })) default = {} @@ -72,8 +75,10 @@ variable "psa_addresses" { type = map(object({ address = string network = string - description = optional(string, "Terraform managed.") prefix_length = number + description = optional(string, "Terraform managed.") + name = optional(string) + })) default = {} } @@ -84,6 +89,7 @@ variable "psc_addresses" { address = string network = string description = optional(string, "Terraform managed.") + name = optional(string) })) default = {} }