Skip to content

Commit

Permalink
Create local with bucket name
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocc committed Jan 20, 2025
1 parent 3e7ce19 commit 8b41ddd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions modules/gcs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
}
)
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/gcs/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions modules/gcs/tags.tf
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 = [
Expand Down

0 comments on commit 8b41ddd

Please sign in to comment.