From c302cf6036cf3419ada127f0dfabeeca39b5234f Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Sat, 30 Dec 2023 16:40:09 -0500 Subject: [PATCH] fix name collisions for allocated ip ranges --- terraform/clouds/gcp/locals.tf | 1 + terraform/clouds/gcp/network.tf | 2 +- terraform/clouds/gcp/variables.tf | 14 ++++++++++++-- test/main.tf | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/terraform/clouds/gcp/locals.tf b/terraform/clouds/gcp/locals.tf index 59fdd51..f3abce3 100644 --- a/terraform/clouds/gcp/locals.tf +++ b/terraform/clouds/gcp/locals.tf @@ -1,4 +1,5 @@ locals { + range_name = var.allocated_range_name == "" ? "${var.cluster_name}-managed-services" : var.allocated_range_name db_url = format("postgresql://console:%s@%s:5432/console", random_password.password.result, try(module.pg[0].private_ip_address, "")) # db_created = var.create_db ? module.pg.0.google_sql_user.default[0] : {} } \ No newline at end of file diff --git a/terraform/clouds/gcp/network.tf b/terraform/clouds/gcp/network.tf index 5de0964..1b30a0a 100644 --- a/terraform/clouds/gcp/network.tf +++ b/terraform/clouds/gcp/network.tf @@ -29,7 +29,7 @@ module "gcp-network" { resource "google_compute_global_address" "private_ip_alloc" { count = var.create_db ? 1 : 0 - name = var.allocated_range + name = local.range_name purpose = "VPC_PEERING" address_type = "INTERNAL" prefix_length = 16 diff --git a/terraform/clouds/gcp/variables.tf b/terraform/clouds/gcp/variables.tf index 8961ea3..d505d99 100644 --- a/terraform/clouds/gcp/variables.tf +++ b/terraform/clouds/gcp/variables.tf @@ -43,46 +43,56 @@ variable "project_id" { } variable "region" { + type = string description = "The region to host the cluster in" default = "us-central1" } variable "network" { + type = string description = "The VPC network created to host the cluster in" default = "plural-network" } variable "subnetwork" { + type = string description = "The subnetwork created to host the cluster in" default = "plural-subnet" } variable "subnet_cidr" { + type = string default = "10.0.0.0/17" } variable "pods_cidr" { + type = string default = "192.168.0.0/18" } -variable "allocated_range" { - default = "google-managed-services-default" +variable "allocated_range_name" { + type = string + default = "" } variable "db_size" { + type = string default = "db-custom-4-8192" } variable "services_cidr" { + type = string default = "192.168.64.0/18" } variable "ip_range_pods_name" { + type = string description = "The secondary ip range to use for pods" default = "ip-range-pods" } variable "ip_range_services_name" { + type = string description = "The secondary ip range to use for services" default = "ip-range-svc" } diff --git a/test/main.tf b/test/main.tf index b6c6478..92291c0 100644 --- a/test/main.tf +++ b/test/main.tf @@ -4,6 +4,7 @@ module "gcp" { cluster_name = "bootstrap-test" network = "plrl-network" subnetwork = "plrl-subnetwork" + allocated_range_name = "google-managed-services" deletion_protection = false }