Skip to content

Commit

Permalink
fix: Automatically truncate VPC peering name if necessary (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
imrannayer authored Jan 15, 2021
1 parent 3491122 commit 67e833a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/network-peering/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 67e833a

Please sign in to comment.