How to conditionally enable/disable a lifecycle_rule for GCP storage buckets

In my module I want to enable or disable a gcp bucket lifecycle_rule based on if a variable is set, so basically I want some buckets to have rule enabled and other buckets ignore the rule setting. But terraform does not have support enabled for a GCP lifecycle_rule that could easily do so (check the AWS link below).

AWS: https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#enabled-1

GCP: https://www.terraform.io/docs/providers/google/r/storage_bucket.html#lifecycle_rule

I’ve tried conditionally setting the rule’s action type and storage_class to “”

    resource "google_storage_bucket" "bucket_ageoff" {
      count = "${var.enable_ageoff}"

      name     = "${local.bucket_name}"
      project  = "${local.project_id}"
      location = "${var.region}"

      storage_class = "${local.bucket_storage_class}"

      encryption {
        default_kms_key_name = "${google_kms_crypto_key.bucket_key.self_link}"
      }

      logging {
        log_bucket = "${google_storage_bucket.log_bucket.name}"
      }

      labels {
        "environment" = "${var.env}"
      }

      lifecycle_rule {
        action {
          type = "Delete"
        }

        condition {
          age = "${var.ageoff_days}"
        }
      }

      lifecycle_rule {
        action {
          type = "${var.coldline_days != ""  ? "SetStorageClass" : ""}"
          storage_class = "${var.coldline_days != ""  ? "COLDLINE" : ""}"
        }

        condition {
          age = "${var.coldline_days != "" ? var.coldline_days : "0"}"
        }
      }

      }
    }

but gcp api gives this error:

1 error(s) occurred:

  • module.log_archive_bucket.google_storage_bucket.bucket_ageoff: 1 error(s) occurred:
  • google_storage_bucket.bucket_ageoff: googleapi: Error 400: Invalid argument, invalid

Below is what I’m actually trying to do:

      ...
      lifecycle_rule {
        //enabled is supported by TF for AWS but not GCP
        //enabled = "${var.coldline_days != "" ? true : false }"

        action {
          type = "SetStorageClass"
          storage_class = "COLDLINE"
        }

        condition {
          age = "${var.coldline_days != "" ? var.coldline_days : "0" }"
        }

      }
    }

Error: module.log_archive_bucket.google_storage_bucket.bucket_ageoff: lifecycle_rule.1: invalid or unknown key: enabled

Any idea to implement the above requirement is appreciated.