From 8b41ddde7772ba6a79cc1d096efeccbaeee45e85 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Mon, 20 Jan 2025 23:56:37 +0100 Subject: [PATCH] Create local with bucket name --- modules/gcs/main.tf | 9 +++++---- modules/gcs/outputs.tf | 4 ++-- modules/gcs/tags.tf | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/gcs/main.tf b/modules/gcs/main.tf index 27bc06480d..f67d5f791c 100644 --- a/modules/gcs/main.tf +++ b/modules/gcs/main.tf @@ -15,6 +15,7 @@ */ locals { + _name = "${local.prefix}${lower(var.name)}" prefix = var.prefix == null ? "" : "${var.prefix}-" notification = try(var.notification_config.enabled, false) topic_create = try(var.notification_config.create_topic, null) != null @@ -25,9 +26,9 @@ locals { url = try(google_storage_bucket.bucket[0].url, null) } : { - name = "${local.prefix}${lower(var.name)}" - id = "${local.prefix}${lower(var.name)}" - url = "gs://${local.prefix}${lower(var.name)}" + name = local._name + id = local._name + url = "gs://${local._name}" } ) } @@ -39,7 +40,7 @@ moved { resource "google_storage_bucket" "bucket" { count = var.bucket_create ? 1 : 0 - name = "${local.prefix}${lower(var.name)}" + name = local._name project = var.project_id location = var.location storage_class = var.storage_class diff --git a/modules/gcs/outputs.tf b/modules/gcs/outputs.tf index 3ad311ea99..c32a0f30f5 100644 --- a/modules/gcs/outputs.tf +++ b/modules/gcs/outputs.tf @@ -27,7 +27,7 @@ output "bucket" { output "id" { description = "Fully qualified bucket id." - value = "${local.prefix}${lower(var.name)}" + value = local._name depends_on = [ google_storage_bucket.bucket, google_storage_bucket_iam_binding.bindings, @@ -38,7 +38,7 @@ output "id" { output "name" { description = "Bucket name." - value = "${local.prefix}${lower(var.name)}" + value = local._name depends_on = [ google_storage_bucket.bucket, google_storage_bucket_iam_binding.bindings, diff --git a/modules/gcs/tags.tf b/modules/gcs/tags.tf index 895605432f..9432411caf 100644 --- a/modules/gcs/tags.tf +++ b/modules/gcs/tags.tf @@ -1,5 +1,5 @@ /** - * Copyright 2022 Google LLC + * Copyright 2025 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ resource "google_tags_location_tag_binding" "binding" { for_each = var.tag_bindings - parent = "//storage.googleapis.com/projects/_/buckets/${local.prefix}${lower(var.name)}" + parent = "//storage.googleapis.com/projects/_/buckets/${local._name}" tag_value = each.value location = var.location depends_on = [