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

On module ""cloud-storage" and sub-module "cloud-storage_simple_bucket", using action type "SetStorageClass" on the "lifecycle_rules" is not working #347

Closed
oralmeida opened this issue Sep 19, 2024 · 2 comments
Labels
bug Something isn't working Stale

Comments

@oralmeida
Copy link

TL;DR

Can't create a bucket using action type "SetStorageClass" on the "lifecycle_rules".
Tried the module "cloud-storage" and sub-module "cloud-storage_simple_bucket" with same result.

Expected behavior

Bucket is created with lifecycle based on SetStorageClass

Observed behavior

Terraform will perform the following actions:

module.cloud-storage_simple_bucket["archive"].google_storage_bucket.bucket will be updated in-place

~ resource "google_storage_bucket" "bucket" {
id = "XXX"
name = "XXX"
# (15 unchanged attributes hidden)

  + lifecycle_rule {
      + action {
          + type = "SetStorageClass"
        }
      + condition {
          + age                   = 60
          + matches_prefix        = []
          + matches_storage_class = []
          + matches_suffix        = []
          + with_state            = (known after apply)
        }
    }

    # (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan

To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"

$ terraform apply "tfplan"
module.cloud-storage_simple_bucket["archive"].google_storage_bucket.bucket: Modifying... [id=XXX]

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

│ with module.cloud-storage_simple_bucket["archive"].google_storage_bucket.bucket,
│ on .terraform/modules/cloud-storage_simple_bucket/modules/simple_bucket/main.tf line 17, in resource "google_storage_bucket" "bucket":
│ 17: resource "google_storage_bucket" "bucket" {

Terraform Configuration

locals {
  buckets = {
    "archive" = {                                                   
      name  = format("%s-%s", "archive-",lower(local.project_id))
      labels = {
        environment = local.environment
      }
      lifecycle_rules = [
        {
          action = {
            type         = "SetStorageClass"
            storageClass = "NEARLINE"
          }
          condition = {
            age          = 60
          }
        }
      ]
      location = upper(var.region)
      versioning               = true 
      storage_class            = "STANDARD"
      public_access_prevention = "enforced"
      randomize_suffix         = true
      set_admin_roles          = true
      set_viewer_roles         = true
      bucket_policy_only = true      
      soft_delete_policy = {
        retention_duration_seconds = 0
      }
    },
    "share" = {
      name  = format("%s-%s", "share-",lower(local.project_id))     
      labels = {
        environment = local.environment
      }
      lifecycle_rules = [{
        action = {
          type = "Delete"
        }
        condition = {
          age = 15
        }
      }]
      location = upper(var.region)
      versioning               = true   
      storage_class            = "STANDARD"
      public_access_prevention = "enforced"
      randomize_suffix         = true
      set_admin_roles          = true
      set_viewer_roles         = true
      
      bucket_policy_only = true         
      soft_delete_policy = {
        retention_duration_seconds = 0
      }
    }
  }
}

module "cloud-storage_simple_bucket" {
  for_each                 = local.buckets
  source                   = "terraform-google-modules/cloud-storage/google//modules/simple_bucket" 
  version                  = "~> 6.1.0"
  project_id               = local.project_id
  labels                   = each.value.labels
  lifecycle_rules          = each.value.lifecycle_rules 
  location                 = each.value.location
  versioning               = each.value.versioning
  storage_class            = each.value.storage_class
  public_access_prevention = each.value.public_access_prevention
  bucket_policy_only       = each.value.bucket_policy_only
  soft_delete_policy       = each.value.soft_delete_policy
  name                     = each.value.name                
}

Terraform Version

Terraform v1.6.2
on linux_amd64
+ provider registry.terraform.io/hashicorp/external v2.3.4
+ provider registry.terraform.io/hashicorp/google v5.42.0
+ provider registry.terraform.io/hashicorp/google-beta v5.42.0
+ provider registry.terraform.io/hashicorp/null v3.2.3
+ provider registry.terraform.io/hashicorp/random v3.6.3

Your version of Terraform is out of date! The latest version
is 1.9.5. You can update by downloading from https://www.terraform.io/downloads.html

Additional information

No response

@oralmeida oralmeida added the bug Something isn't working label Sep 19, 2024
@sunny-1651
Copy link

sunny-1651 commented Oct 22, 2024

Inside actions object it should be storage_class instead of storageClass.
Since the keyword is wrong the target storage class is going as null and that could be an issue

Copy link

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

@github-actions github-actions bot added the Stale label Dec 21, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

2 participants