Query on Resource - google_storage_bucket

Can someone help me whats the syntax I should use to update a lifecycle rule on a bucket for

I have a use-case where a developer wanted me to change the lifecycle rule to enable “DaysSinceCustomTime”[1] and its references on the Google console are based on days while in Terraform its value representation is in the form of yyyy-mm-dd how do I refer to 5 days in this format?

[1]Object Lifecycle Management  |  Cloud Storage  |  Google Cloud

This seems to be a bug in the Google provider documentation. The source code shows that the type is an integer, and the comment indicates that it represents the number of days.

In my testing, assigning 5 as the value works as expected and results in the expected lifecycle rules when looking in the Google Cloud Console.

resource "google_storage_bucket" "bucket" {
  name          = local.bucket_name
  location      = "US"
  force_destroy = true

  lifecycle_rule {
    condition {
      days_since_custom_time = 5
    action {
      type = "Delete"

If you feel up to reporting the docs bug on the provider, that would save someone else from hitting this same problem!

Thanks for the response @alisdair

I tried doing the same it doesn’t work for me I get HTTP 400 bad request

  lifecycle_rules = [{
action = {
  type = "Delete"
condition = {
  days_since_custom_time        = 10

I am using the code referenced here[1] to create the buckets

[1] GitHub - terraform-google-modules/terraform-google-cloud-storage: This module makes it easy to create one or more GCS buckets, and assign basic permissions on them to arbitrary users.

Huh! I’m not sure what the cause is there. If you can share more information about the error, maybe that will reveal something?

Since it definitely worked for me in isolation (with my config in the first reply) this might be an issue with the module.

I am getting 400 Bad requests, doesn’t look like a Terraform error

Error: googleapi: Error 400: Invalid argument, invalid
{“error”:{“code”:400,“message”:“Invalid argument”,“errors”:[{“message”:“Invalid argument”,“domain”:“global”,“reason”:“invalid”}]}}:

I have raised a documentation bug

I shall spend sometime debugging the error

Its works @alisdair I found the issue, the module did not have the argument days_since_custom_time defined in the block

hopefully, the documentation gets fixed

1 Like