From de5adb0cd81964d73307d98a3e8e1f7e7b76d63e Mon Sep 17 00:00:00 2001 From: Alex Lo Date: Thu, 10 Oct 2024 11:24:31 -0300 Subject: [PATCH] Fix: always specify Terraform project (#384) * fix: always specify project * fix: use supplied project ID explicitly --------- Co-authored-by: henrybell --- terraform/modules/autoscaler-base/main.tf | 5 ++++- terraform/modules/autoscaler-cluster/main.tf | 5 +++++ terraform/modules/autoscaler-functions/main.tf | 7 +++++-- terraform/modules/forwarder/main.tf | 6 +++++- terraform/modules/scheduler/main.tf | 1 + 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/terraform/modules/autoscaler-base/main.tf b/terraform/modules/autoscaler-base/main.tf index 54ed5a23..4089c486 100644 --- a/terraform/modules/autoscaler-base/main.tf +++ b/terraform/modules/autoscaler-base/main.tf @@ -24,7 +24,8 @@ resource "google_project_iam_member" "poller_sa_spanner" { // Downstream topic resource "google_pubsub_topic" "downstream_topic" { - name = "downstream-topic" + project = var.project_id + name = "downstream-topic" depends_on = [google_pubsub_schema.scaler_downstream_pubsub_schema] @@ -46,6 +47,7 @@ resource "google_pubsub_topic_iam_member" "scaler_downstream_pub_iam" { } resource "google_pubsub_schema" "scaler_downstream_pubsub_schema" { + project = var.project_id name = "downstream-schema" type = "PROTOCOL_BUFFER" definition = file("${path.module}/../../../src/scaler/scaler-core/downstream.schema.proto") @@ -64,6 +66,7 @@ resource "google_project_iam_member" "metrics_publisher_iam_scaler" { } resource "google_service_account" "build_sa" { + project = var.project_id account_id = "build-sa" display_name = "Autoscaler - Cloud Build Builder Service Account" } diff --git a/terraform/modules/autoscaler-cluster/main.tf b/terraform/modules/autoscaler-cluster/main.tf index 930e4b09..def3a430 100644 --- a/terraform/modules/autoscaler-cluster/main.tf +++ b/terraform/modules/autoscaler-cluster/main.tf @@ -80,11 +80,13 @@ resource "google_project_iam_member" "cluster_iam_artifactregistryreader" { // Other resources resource "google_compute_network" "network" { + project = var.project_id name = "spanner-autoscaler-network" auto_create_subnetworks = false } resource "google_compute_subnetwork" "subnetwork" { + project = var.project_id name = "spanner-autoscaler-subnetwork" network = google_compute_network.network.id ip_cidr_range = "10.0.0.0/16" @@ -92,11 +94,13 @@ resource "google_compute_subnetwork" "subnetwork" { } resource "google_compute_router" "router" { + project = var.project_id name = "app-router" network = google_compute_network.network.id } resource "google_compute_router_nat" "nat" { + project = var.project_id name = "autoscaler-nat" router = google_compute_router.router.name region = google_compute_router.router.region @@ -110,6 +114,7 @@ resource "google_compute_router_nat" "nat" { } resource "google_artifact_registry_repository" "autoscaler_artifact_repo" { + project = var.project_id location = var.region repository_id = "spanner-autoscaler" description = "Image registry for Spanner Autoscaler" diff --git a/terraform/modules/autoscaler-functions/main.tf b/terraform/modules/autoscaler-functions/main.tf index d28d5a41..ef194dab 100644 --- a/terraform/modules/autoscaler-functions/main.tf +++ b/terraform/modules/autoscaler-functions/main.tf @@ -23,7 +23,8 @@ terraform { // PubSub resource "google_pubsub_topic" "poller_topic" { - name = "poller-topic" + project = var.project_id + name = "poller-topic" } resource "google_pubsub_topic_iam_member" "poller_pubsub_sub_iam" { @@ -43,7 +44,8 @@ resource "google_pubsub_topic_iam_member" "forwarder_pubsub_pub_iam" { } resource "google_pubsub_topic" "scaler_topic" { - name = "scaler-topic" + project = var.project_id + name = "scaler-topic" } resource "google_pubsub_topic_iam_member" "poller_pubsub_pub_iam" { @@ -63,6 +65,7 @@ resource "google_pubsub_topic_iam_member" "scaler_pubsub_sub_iam" { // Cloud Functions resource "google_storage_bucket" "bucket_gcf_source" { + project = var.project_id name = "${var.project_id}-gcf-source" storage_class = "REGIONAL" location = var.region diff --git a/terraform/modules/forwarder/main.tf b/terraform/modules/forwarder/main.tf index 92291251..48be0b76 100644 --- a/terraform/modules/forwarder/main.tf +++ b/terraform/modules/forwarder/main.tf @@ -18,6 +18,7 @@ // Service Accounts resource "google_service_account" "build_sa" { + project = var.project_id account_id = "build-sa" display_name = "Autoscaler - Cloud Build Builder Service Account" } @@ -39,6 +40,7 @@ resource "time_sleep" "wait_for_iam" { } resource "google_service_account" "forwarder_sa" { + project = var.project_id account_id = "forwarder-sa" display_name = "Autoscaler - PubSub Forwarder Service Account" } @@ -46,7 +48,8 @@ resource "google_service_account" "forwarder_sa" { // PubSub resource "google_pubsub_topic" "forwarder_topic" { - name = "forwarder-topic" + project = var.project_id + name = "forwarder-topic" } resource "google_pubsub_topic_iam_member" "forwader_pubsub_sub_binding" { @@ -59,6 +62,7 @@ resource "google_pubsub_topic_iam_member" "forwader_pubsub_sub_binding" { // Cloud Functions resource "google_storage_bucket" "bucket_gcf_source" { + project = var.project_id name = "${var.project_id}-gcf-source" storage_class = "REGIONAL" location = var.region diff --git a/terraform/modules/scheduler/main.tf b/terraform/modules/scheduler/main.tf index ebccd27e..6bf804a8 100644 --- a/terraform/modules/scheduler/main.tf +++ b/terraform/modules/scheduler/main.tf @@ -44,6 +44,7 @@ resource "google_app_engine_application" "app" { } resource "google_cloud_scheduler_job" "poller_job" { + project = var.project_id name = "poll-main-instance-metrics" description = "Poll metrics for main-instance" schedule = var.schedule