最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

terraform - Failing to create a google GCS bucket because of googleapi: Error 400: Invalid argument., invalid - Stack Overflow

programmeradmin3浏览0评论

I'm getting a googleapi: Error 400: Invalid argument., invalid with no additional information at all. And I have absolutely no clue what is causing this. The bucket name is compliant AFAIK.

Error: googleapi: Error 400: Invalid argument., invalid

with module.buckets["customer-user-bio-ew2-rmv-dev"].module.gcs_bucket.google_storage_bucket.bucket,
on .terraform/modules/buckets.gcs_bucket/modules/simple_bucket/main.tf line 22, in resource "google_storage_bucket" "bucket":
22: resource "google_storage_bucket" "bucket" {

The TF code

module "buckets" {
  for_each                               = var.buckets
  source                                 = "source pasted below"
  version                                = "3.2.0"
  bucket_name                            = each.key
  project                                = var.project_id
  location                               = each.value["location"]
  storage_class                          = each.value["storage_class"]
  versioning                             = each.value["versioning"]
  create_generic_storage_object_admin_sa = each.value["create_generic_storage_object_admin_sa"]
  storage_object_viewers                 = each.value["storage_object_viewers"]
  storage_object_users                   = each.value["storage_object_users"]
  lifecycle_rules                        = each.value["lifecycle_rules"]
  depends_on                             = [google_service_account.service_accounts]
  enforced_labels                        = each.value["enforced_labels"]
}

inputs = {  
    ...
    ...
    buckets = {
        "some-name-${local.environment}" = {
          project                                = local.project_id
          location                               = "europe-west2"
          storage_class                          = "STANDARD"
          versioning                             = false
          storage_object_viewers                 = [..]
          storage_object_users                   = [..]
          create_generic_storage_object_admin_sa = false
          lifecycle_rules = [{
            condition = {
              age                        = 0    # immediately
              num_newer_versions         = null # Max number of versions to keep per object
              days_since_noncurrent_time = null # Expire non-current versions after x days
            }
            action = {
              type          = "SetStorageClass"
              storage_class = "STANDARD"
            }
          }]
          enforced_labels = {
            owner       = "some-team"
            environment = local.environment
          }
        }
}

the source module

module "gcs_bucket" {
  source           = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
  version          = "9.1.0"
  project_id       = var.project
  name             = var.bucket_name
  location         = var.location
  storage_class    = var.storage_class
  versioning       = var.versioning
  retention_policy = var.retention_policy
  lifecycle_rules  = var.lifecycle_rules
  labels           = merge(var.enforced_labels, var.optional_labels)
}

Any sort of clues would be welcome!

I tried changing the bucket name, changing the service account names, removing the lifecycles rules

I'm getting a googleapi: Error 400: Invalid argument., invalid with no additional information at all. And I have absolutely no clue what is causing this. The bucket name is compliant AFAIK.

Error: googleapi: Error 400: Invalid argument., invalid

with module.buckets["customer-user-bio-ew2-rmv-dev"].module.gcs_bucket.google_storage_bucket.bucket,
on .terraform/modules/buckets.gcs_bucket/modules/simple_bucket/main.tf line 22, in resource "google_storage_bucket" "bucket":
22: resource "google_storage_bucket" "bucket" {

The TF code

module "buckets" {
  for_each                               = var.buckets
  source                                 = "source pasted below"
  version                                = "3.2.0"
  bucket_name                            = each.key
  project                                = var.project_id
  location                               = each.value["location"]
  storage_class                          = each.value["storage_class"]
  versioning                             = each.value["versioning"]
  create_generic_storage_object_admin_sa = each.value["create_generic_storage_object_admin_sa"]
  storage_object_viewers                 = each.value["storage_object_viewers"]
  storage_object_users                   = each.value["storage_object_users"]
  lifecycle_rules                        = each.value["lifecycle_rules"]
  depends_on                             = [google_service_account.service_accounts]
  enforced_labels                        = each.value["enforced_labels"]
}

inputs = {  
    ...
    ...
    buckets = {
        "some-name-${local.environment}" = {
          project                                = local.project_id
          location                               = "europe-west2"
          storage_class                          = "STANDARD"
          versioning                             = false
          storage_object_viewers                 = [..]
          storage_object_users                   = [..]
          create_generic_storage_object_admin_sa = false
          lifecycle_rules = [{
            condition = {
              age                        = 0    # immediately
              num_newer_versions         = null # Max number of versions to keep per object
              days_since_noncurrent_time = null # Expire non-current versions after x days
            }
            action = {
              type          = "SetStorageClass"
              storage_class = "STANDARD"
            }
          }]
          enforced_labels = {
            owner       = "some-team"
            environment = local.environment
          }
        }
}

the source module

module "gcs_bucket" {
  source           = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
  version          = "9.1.0"
  project_id       = var.project
  name             = var.bucket_name
  location         = var.location
  storage_class    = var.storage_class
  versioning       = var.versioning
  retention_policy = var.retention_policy
  lifecycle_rules  = var.lifecycle_rules
  labels           = merge(var.enforced_labels, var.optional_labels)
}

Any sort of clues would be welcome!

I tried changing the bucket name, changing the service account names, removing the lifecycles rules

Share Improve this question asked Mar 11 at 11:16 abdo98abdo98 215 bronze badges 3
  • can you double-check the bucket name to ensure it meets the naming requirements? Also, can you confirm what exactly is on line 22 of your main.tf file?You might check this answer as well – Sathi Aiswarya Commented Mar 11 at 14:13
  • Just fixed it! See answer below! (yep the bucket name was meeting the requirements) – abdo98 Commented Mar 11 at 15:16
  • @SathiAiswarya also, line 22 was simply refering to the google simple_bucket definition – abdo98 Commented Mar 11 at 17:29
Add a comment  | 

1 Answer 1

Reset to default 0

Fixed by modifying the lifecycle rules to:

condition = {
  age = 1
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论