terraform-google-modules/terraform-google-cloud-storage

Module fails when names list is empty

tpolekhin opened this issue · 1 comments

TL;DR

Sometimes you want to create buckets conditionally.
Passing in an empty list for the names parameter breaks the module.

Expected behavior

Module should not create any resources

Observed behavior

Module fails with:

│ Error: Invalid index
│ 
│   on .terraform/modules/gcs/main.tf line 29, in locals:
│   29:   first_bucket = local.buckets_list[0]
│     ├────────────────
│     │ local.buckets_list is empty tuple
│ 
│ The given key does not identify an element in this collection value: the
│ collection has no elements.

Terraform Configuration

module "gcs" {
  source  = "terraform-google-modules/cloud-storage/google"
  version = "3.3.0"

  project_id       = var.project_id
  names            = local.create_gcs_bucket ? ["testbucket"] : []
  randomize_suffix = local.create_gcs_bucket # dont create random_id if we don't create buckets
  location         = var.region
  labels           = local.labels
}

Terraform Version

Terraform v1.1.2
on darwin_amd64
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/google v4.41.0
+ provider registry.terraform.io/hashicorp/google-beta v4.41.0
+ provider registry.terraform.io/hashicorp/null v3.1.1
+ provider registry.terraform.io/hashicorp/random v3.4.3

Additional information

No response

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days