From c61e81c07500a7d6c30ae300d0e8cff60d09877d Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Fri, 28 Apr 2023 15:53:39 +1000 Subject: [PATCH 1/2] fix: make sure subnet is uniquely named --- infra/postdeployment.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/postdeployment.tf b/infra/postdeployment.tf index c81f2675..823192c8 100644 --- a/infra/postdeployment.tf +++ b/infra/postdeployment.tf @@ -24,7 +24,7 @@ module "gce-vpc" { subnets = [ { - subnet_name = "subnet-gce-int" + subnet_name = var.random_suffix ? "subnet-gce-init-${random_id.suffix.hex}" : "subnet-gce-init" subnet_ip = "10.10.10.0/24" subnet_region = var.region } From 29214983fc2f66863ed3beb8d56e78fc724c4e5e Mon Sep 17 00:00:00 2001 From: Katie McLaughlin Date: Mon, 1 May 2023 14:28:46 +1000 Subject: [PATCH 2/2] feat: replace gce-vpc module with plain resources --- infra/postdeployment.tf | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/infra/postdeployment.tf b/infra/postdeployment.tf index 823192c8..63ed7f24 100644 --- a/infra/postdeployment.tf +++ b/infra/postdeployment.tf @@ -14,27 +14,29 @@ * limitations under the License. */ +resource "google_compute_network" "gce_init" { + count = var.init ? 1 : 0 -module "gce-vpc" { - count = var.init ? 1 : 0 - source = "terraform-google-modules/network/google" - version = "~> 7.0" - project_id = var.project_id - network_name = var.random_suffix ? "gce-init-network-${random_id.suffix.hex}" : "gce-init-network" - - subnets = [ - { - subnet_name = var.random_suffix ? "subnet-gce-init-${random_id.suffix.hex}" : "subnet-gce-init" - subnet_ip = "10.10.10.0/24" - subnet_region = var.region - } - ] + name = var.random_suffix ? "gce-init-network-${random_id.suffix.hex}" : "gce-init-network" + auto_create_subnetworks = false + routing_mode = "GLOBAL" + project = var.project_id + delete_default_routes_on_create = false + mtu = 0 +} - depends_on = [google_project_service.enabled] +resource "google_compute_subnetwork" "gce_init" { + count = var.init ? 1 : 0 + + name = var.random_suffix ? "subnet-gce-init-${random_id.suffix.hex}" : "subnet-gce-init" + network = google_compute_network.gce_init[0].id + ip_cidr_range = "10.10.10.0/24" + region = var.region } -resource "google_compute_instance" "initialize" { +resource "google_compute_instance" "gce_init" { count = var.init ? 1 : 0 + depends_on = [ google_project_service.enabled, google_sql_database_instance.postgres, @@ -56,8 +58,8 @@ resource "google_compute_instance" "initialize" { } network_interface { - network = module.gce-vpc[0].network_self_link - subnetwork = module.gce-vpc[0].subnets_self_links[0] + network = google_compute_network.gce_init[0].self_link + subnetwork = google_compute_subnetwork.gce_init[0].self_link access_config { // Ephemeral public IP