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

matches_prefix on gcs lifecycle management not working with terraform

Closed this issue · 1 comments

TL;DR

Hi Team,
I am using terraform to deploy lifecycle_rules for gcs , but when deploying the terraform plan not showing error but the defined matches_prefix not showing in the plan output. It is coming as blank (i.e. [])for all.

Expected behavior

Terraform plan should show matches_prefix on the lifecycle_rules on the bucket where the condition applied.
Also, this should work because using provider version which is supported this (4.32.0)
https://registry.terraform.io/providers/hashicorp/google/4.32.0/docs/resources/storage_bucket

Observed behavior

Output of terraform plan for a specific bucket :
~ gcs2 = {
~ bucket = {
+ autoclass = []
- bucket_policy_only = false -> null
+ custom_placement_config = []
~ lifecycle_rule = [] -> [
+ {
+ action = [
+ {
+ storage_class = ""
+ type = "Delete"
},
]
+ condition = [
+ {
+ age = 15
+ created_before = ""
+ custom_time_before = ""
+ days_since_custom_time = null
+ days_since_noncurrent_time = null
+ matches_prefix = []
+ matches_storage_class = []
+ matches_suffix = []
+ noncurrent_time_before = ""
+ num_newer_versions = null
+ with_state = (known after apply)
},
]
},
]

Terraform Configuration

tfvar file:
  "gcs2" = {
    bucket_policy_only = false
    bucket_name        = "bucket-name"
    labels = {
      "eu" : "abc"
      "env" : "prod"
      "resource_name" : "bucket-name"
    }
    iam_members = []
    storage_class = "STANDARD"
    versioning    = false
    lifecycle_rules = [{
      action = {
        type = "Delete"
      }
      condition = {
        age            = 15
        matches_prefix = ["subpath1/subpath2/"]
      }
    }]
  },
variable.tf:
####################
# gcs data buckets #
####################

variable "gcs_configs" {
  type = map(object({
    bucket_policy_only = bool
    bucket_name        = string
    labels             = map(any)
    iam_members        = list(map(any))
    storage_class      = string
    versioning         = bool
    lifecycle_rules    = list(object({
      action    = map(any),
      condition = object({
        age            = number
        matches_prefix = list(string)
      })
    }))
  }))
gcs.tf:
module "gcs" {
  source     = "git::https://github.com<path-where-main-module-is-present>/generic-modules/compute/gcs/?ref=1.4.0"
  depends_on = [module.gcs_bucket_access_sa]
  project_id = var.project_id
  location   = var.region

  for_each           = var.gcs_configs
  bucket_policy_only = each.value.bucket_policy_only
  name               = each.value.bucket_name
  labels             = each.value.labels

  iam_members   = each.value.iam_members
  storage_class = each.value.storage_class
  versioning    = each.value.versioning
  lifecycle_rules = each.value.lifecycle_rules
}

Terraform Version

terraform {
  required_version = ">= 1.0.0"
  required_providers {
    google      = "~> 4.32"
    google-beta = "~> 4.32"
    random      = "~> 2.2"
    null        = "~> 2.1"
  }
}

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