Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to append a randomized suffix to all bucket names #130

Merged
merged 1 commit into from
Sep 10, 2021
Merged

Add ability to append a randomized suffix to all bucket names #130

merged 1 commit into from
Sep 10, 2021

Conversation

tpdownes
Copy link
Member

@tpdownes tpdownes commented Sep 9, 2021

Google Cloud Storage buckets need globally unique names. Therefore, it's helpful to have a randomized component to names, especially for use in example code. The following code

resource "random_id" "bucket" {
  byte_length = 2
}

module "example_bucket" {
  source     = "terraform-google-modules/cloud-storage/google"
  version    = "~> 2.1"
  project_id = var.project_id
  location   = var.region

  prefix = "myproject"
  names  = ["data-${random_id.bucket.hex}"]
  versioning = {
    "data" : true
  }
  storage_class = "REGIONAL"
  admins = [
    module.sa_example.iam_email
  ]
  depends_on = [
    module.project_services
  ]
}

results in an error

│ The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this,
│ use the -target argument to first apply only the resources that the for_each depends on.

This is for well-understood reasons about terraform plan and iteration. The project-factory module is subject to similar uniqueness requirements and resolves this issue by creating a random resource inside the module. This PR imitates that solution closely in order to aid the user (and developers of examples) to automatically create unique buckets that remain identifiable by eye.

@comment-bot-dev
Copy link

comment-bot-dev commented Sep 9, 2021

Thanks for the PR! 🚀
✅ Lint checks have passed.

@tpdownes tpdownes mentioned this pull request Sep 9, 2021
@morgante morgante merged commit 93ff75f into terraform-google-modules:master Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants