diff --git a/README.md b/README.md index 2a267711..cd853627 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Functional examples are included in the | location | Bucket location. | `string` | `"EU"` | no | | logging | Map of lowercase unprefixed name => bucket logging config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#logging | `any` | `{}` | no | | names | Bucket name suffixes. | `list(string)` | n/a | yes | -| prefix | Prefix used to generate the bucket name. | `string` | n/a | yes | +| prefix | Prefix used to generate the bucket name. | `string` | `""` | no | | project\_id | Bucket project id. | `string` | n/a | yes | | randomize\_suffix | Adds an identical, but randomized 4-character suffix to all bucket names | `bool` | `false` | no | | retention\_policy | Map of retention policy values. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket#retention_policy | `any` | `{}` | no | diff --git a/docs/upgrading_to_v4.0.md b/docs/upgrading_to_v4.0.md new file mode 100644 index 00000000..5c4531ea --- /dev/null +++ b/docs/upgrading_to_v4.0.md @@ -0,0 +1,42 @@ +# Upgrading to v4.0 + +The v4.0 release of the terraform-google-cloud-storage module is a backwards incompatible release, due to the following breaking changes: + +- The bucket doesn't have location as mandatory part of the name prefix. + +## Migration Instructions + +A migration from 3.x to 4.x as showcased below + +```diff +module "cloud_storage" { + source = "terraform-google-modules/cloud-storage/google" +- version = "~> 3.0" ++ version = "~> 4.0" +``` +will produce the following output during a `terraform plan`: + +```bash +# module.cloud_storage.google_storage_bucket.buckets["one"] must be replaced +... +~ name = "multiple-buckets-iost-eu-one" -> "multiple-buckets-iost-one" # forces replacement +... +# module.cloud_storage.google_storage_bucket.buckets["two"] must be replaced +... +~ name = "multiple-buckets-iost-eu-two" -> "multiple-buckets-iost-two" # forces replacement +... +Plan: 2 to add, 0 to change, 2 to destroy. +``` + +In the module bucket prefix contained `location` before. To preserve the same bucket name with `location` in prefix you should make some code adjustments: + +```diff +- prefix = "multiple-buckets-${random_string.prefix.result}" ++ prefix = "multiple-buckets-${random_string.prefix.result}-eu" +``` + +Re-running the plan should show that the storage bucket resources are no longer showing a diff. + +``` +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. +``` diff --git a/main.tf b/main.tf index c3e7fdae..9440cf31 100644 --- a/main.tf +++ b/main.tf @@ -22,8 +22,7 @@ resource "random_id" "bucket_suffix" { } locals { - prefix = var.prefix == "" ? "" : join("-", [var.prefix, lower(var.location), ""]) - suffix = var.randomize_suffix ? "-${random_id.bucket_suffix.hex}" : "" + suffix = var.randomize_suffix ? random_id.bucket_suffix.hex : "" names_set = toset(var.names) buckets_list = [for name in var.names : google_storage_bucket.buckets[name]] first_bucket = local.buckets_list[0] @@ -40,11 +39,11 @@ locals { resource "google_storage_bucket" "buckets" { for_each = local.names_set - name = "${local.prefix}${lower(each.value)}${local.suffix}" + name = join("-", compact([var.prefix, each.value, local.suffix])) project = var.project_id location = var.location storage_class = var.storage_class - labels = merge(var.labels, { name = replace("${local.prefix}${lower(each.value)}", ".", "-") }) + labels = merge(var.labels, { name = replace(join("-", compact([var.prefix, each.value])), ".", "-") }) force_destroy = lookup( var.force_destroy, lower(each.value), diff --git a/variables.tf b/variables.tf index 275cf9c9..6ea40dc0 100644 --- a/variables.tf +++ b/variables.tf @@ -22,6 +22,7 @@ variable "project_id" { variable "prefix" { description = "Prefix used to generate the bucket name." type = string + default = "" } variable "names" {