From bdb467d51b8c6dcf3740cb42633bd352c732fa3b Mon Sep 17 00:00:00 2001 From: mariammartins Date: Wed, 9 Oct 2024 10:31:09 -0300 Subject: [PATCH 1/2] fix bucket names --- 1-org/modules/cai-monitoring/main.tf | 5 +++-- 4-projects/modules/base_env/example_storage_cmek.tf | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/1-org/modules/cai-monitoring/main.tf b/1-org/modules/cai-monitoring/main.tf index 22d6425ff..039444962 100644 --- a/1-org/modules/cai-monitoring/main.tf +++ b/1-org/modules/cai-monitoring/main.tf @@ -26,7 +26,8 @@ locals { "run.googleapis.com", "eventarc.googleapis.com" ] - cai_source_name = var.random_suffix ? "CAI Monitoring - ${random_id.suffix.hex}" : "CAI Monitoring" + cai_source_name = var.random_suffix ? "CAI Monitoring - ${random_id.suffix.hex}" : "CAI Monitoring" + cai_monitoring_bucket_suffix = "${random_id.suffix.hex}-sources-${data.google_project.project.number}-${var.location}" } data "google_project" "project" { @@ -74,7 +75,7 @@ module "cloudfunction_source_bucket" { version = "~> 6.0" project_id = var.project_id - name = "bkt-cai-monitoring-${random_id.suffix.hex}-sources-${data.google_project.project.number}-${var.location}" + name = "bkt-cai-monitoring-${md5(local.cai_monitoring_bucket_suffix)}" location = var.location storage_class = "REGIONAL" force_destroy = true diff --git a/4-projects/modules/base_env/example_storage_cmek.tf b/4-projects/modules/base_env/example_storage_cmek.tf index 8b40250a7..cafde4143 100644 --- a/4-projects/modules/base_env/example_storage_cmek.tf +++ b/4-projects/modules/base_env/example_storage_cmek.tf @@ -14,6 +14,11 @@ * limitations under the License. */ +locals { + cmek_bucket_prefix = "${var.gcs_bucket_prefix}-cmek-encrypted" + cmek_bucket_suffix = "${module.base_shared_vpc_project.project_id}-${lower(var.location_gcs)}-${random_string.bucket_name.result}" +} + data "google_storage_project_service_account" "gcs_account" { project = module.base_shared_vpc_project.project_id } @@ -44,11 +49,11 @@ resource "random_string" "bucket_name" { module "gcs_buckets" { source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket" - version = "~> 6.0" + version = "~> 6.0.0" project_id = module.base_shared_vpc_project.project_id location = var.location_gcs - name = "${var.gcs_bucket_prefix}-${module.base_shared_vpc_project.project_id}-${lower(var.location_gcs)}-cmek-encrypted-${random_string.bucket_name.result}" + name = "${local.cmek_bucket_prefix}-${md5(local.cmek_bucket_suffix)}" bucket_policy_only = true custom_placement_config = var.gcs_custom_placement_config From 7c7a1ef0b8d286ddb63a8b7574fbb44de01e64cb Mon Sep 17 00:00:00 2001 From: mariammartins Date: Wed, 9 Oct 2024 12:06:33 -0300 Subject: [PATCH 2/2] change in bucket name --- 1-org/modules/cai-monitoring/main.tf | 5 ++--- 4-projects/modules/base_env/example_storage_cmek.tf | 7 +------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/1-org/modules/cai-monitoring/main.tf b/1-org/modules/cai-monitoring/main.tf index 039444962..95f1761b1 100644 --- a/1-org/modules/cai-monitoring/main.tf +++ b/1-org/modules/cai-monitoring/main.tf @@ -26,8 +26,7 @@ locals { "run.googleapis.com", "eventarc.googleapis.com" ] - cai_source_name = var.random_suffix ? "CAI Monitoring - ${random_id.suffix.hex}" : "CAI Monitoring" - cai_monitoring_bucket_suffix = "${random_id.suffix.hex}-sources-${data.google_project.project.number}-${var.location}" + cai_source_name = var.random_suffix ? "CAI Monitoring - ${random_id.suffix.hex}" : "CAI Monitoring" } data "google_project" "project" { @@ -75,7 +74,7 @@ module "cloudfunction_source_bucket" { version = "~> 6.0" project_id = var.project_id - name = "bkt-cai-monitoring-${md5(local.cai_monitoring_bucket_suffix)}" + name = "bkt-cai-monitoring-${random_id.suffix.hex}-sources-${data.google_project.project.number}" location = var.location storage_class = "REGIONAL" force_destroy = true diff --git a/4-projects/modules/base_env/example_storage_cmek.tf b/4-projects/modules/base_env/example_storage_cmek.tf index cafde4143..cd10c2a38 100644 --- a/4-projects/modules/base_env/example_storage_cmek.tf +++ b/4-projects/modules/base_env/example_storage_cmek.tf @@ -14,11 +14,6 @@ * limitations under the License. */ -locals { - cmek_bucket_prefix = "${var.gcs_bucket_prefix}-cmek-encrypted" - cmek_bucket_suffix = "${module.base_shared_vpc_project.project_id}-${lower(var.location_gcs)}-${random_string.bucket_name.result}" -} - data "google_storage_project_service_account" "gcs_account" { project = module.base_shared_vpc_project.project_id } @@ -53,7 +48,7 @@ module "gcs_buckets" { project_id = module.base_shared_vpc_project.project_id location = var.location_gcs - name = "${local.cmek_bucket_prefix}-${md5(local.cmek_bucket_suffix)}" + name = "${var.gcs_bucket_prefix}-${module.base_shared_vpc_project.project_id}-cmek-encrypted-${random_string.bucket_name.result}" bucket_policy_only = true custom_placement_config = var.gcs_custom_placement_config