From 23b305ad3128466c23e286602945916a44e255cd Mon Sep 17 00:00:00 2001 From: policy-librarians Date: Mon, 23 Oct 2023 20:43:41 +0000 Subject: [PATCH] more changes --- examples/cloud_storage/README.md | 3 ++- examples/cloud_storage/main.tf | 11 ++++++++--- examples/cloud_storage/outputs.tf | 4 ++-- examples/cloud_storage/variables.tf | 8 ++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/cloud_storage/README.md b/examples/cloud_storage/README.md index 93b8998..07ae999 100644 --- a/examples/cloud_storage/README.md +++ b/examples/cloud_storage/README.md @@ -7,8 +7,9 @@ This example illustrates how to use the `pubsub` module. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| bucket\_name | The name of the GCS bucket name to which to write messages | `string` | n/a | yes | +| bucket\_name | The name of the GCS bucket name to which to write messages | `string` | `"test_bucket"` | no | | project\_id | The project ID to manage the Pub/Sub resources | `string` | n/a | yes | +| random\_bucket\_suffix | Add a randomized 4-character suffix to bucket name | `bool` | `true` | no | ## Outputs diff --git a/examples/cloud_storage/main.tf b/examples/cloud_storage/main.tf index f2f39cc..2969b62 100644 --- a/examples/cloud_storage/main.tf +++ b/examples/cloud_storage/main.tf @@ -1,5 +1,5 @@ /** - * Copyright 2018 Google LLC + * Copyright 2018-2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,11 @@ * limitations under the License. */ +resource "random_id" "bucket_suffix" { + count = var.random_bucket_suffix ? 1 : 0 + byte_length = 4 +} + provider "google" { region = "europe-west1" } @@ -26,7 +31,7 @@ module "pubsub" { cloud_storage_subscriptions = [ { name = "example_subscription" - bucket = var.bucket_name + bucket = google_storage_bucket.test.name }, ] @@ -38,6 +43,6 @@ module "pubsub" { resource "google_storage_bucket" "test" { project = var.project_id - name = var.bucket_name + name = var.random_bucket_suffix ? join("-", [var.bucket_name, random_id.bucket_suffix]) : var.bucket_name location = "europe-west1" } diff --git a/examples/cloud_storage/outputs.tf b/examples/cloud_storage/outputs.tf index 48c833d..073d4cc 100644 --- a/examples/cloud_storage/outputs.tf +++ b/examples/cloud_storage/outputs.tf @@ -1,5 +1,5 @@ /** - * Copyright 2018 Google LLC + * Copyright 2018-2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ output "project_id" { } output "bucket_name" { - value = var.bucket_name + value = google_storage_bucket.test.name description = "The name of the Cloud Storage bucket created" } diff --git a/examples/cloud_storage/variables.tf b/examples/cloud_storage/variables.tf index a9c54de..d71e3aa 100644 --- a/examples/cloud_storage/variables.tf +++ b/examples/cloud_storage/variables.tf @@ -18,7 +18,15 @@ variable "project_id" { type = string description = "The project ID to manage the Pub/Sub resources" } + variable "bucket_name" { type = string description = "The name of the GCS bucket name to which to write messages" + default = "test_bucket" +} + +variable "random_bucket_suffix" { + type = bool + description = "Add a randomized 4-character suffix to bucket name" + default = true }