diff --git a/modules/network-peering/main.tf b/modules/network-peering/main.tf index bcb52123..d352798f 100644 --- a/modules/network-peering/main.tf +++ b/modules/network-peering/main.tf @@ -17,11 +17,22 @@ locals { local_network_name = element(reverse(split("/", var.local_network)), 0) peer_network_name = element(reverse(split("/", var.peer_network)), 0) + + local_network_peering = "${var.prefix}-${local.local_network_name}-${local.peer_network_name}" + local_network_peering_name = length(local.local_network_peering) < 63 ? local.local_network_peering : "${substr(local.local_network_peering, 0, min(58, length(local.local_network_peering)))}-${random_string.network_peering_suffix.result}" + peer_network_peering = "${var.prefix}-${local.peer_network_name}-${local.local_network_name}" + peer_network_peering_name = length(local.peer_network_peering) < 63 ? local.peer_network_peering : "${substr(local.peer_network_peering, 0, min(58, length(local.peer_network_peering)))}-${random_string.network_peering_suffix.result}" } +resource "random_string" "network_peering_suffix" { + upper = false + lower = true + special = false + length = 4 +} resource "google_compute_network_peering" "local_network_peering" { provider = google-beta - name = "${var.prefix}-${local.local_network_name}-${local.peer_network_name}" + name = local.local_network_peering_name network = var.local_network peer_network = var.peer_network export_custom_routes = var.export_local_custom_routes @@ -32,7 +43,7 @@ resource "google_compute_network_peering" "local_network_peering" { resource "google_compute_network_peering" "peer_network_peering" { provider = google-beta - name = "${var.prefix}-${local.peer_network_name}-${local.local_network_name}" + name = local.peer_network_peering_name network = var.peer_network peer_network = var.local_network export_custom_routes = var.export_peer_custom_routes