diff --git a/CHANGELOG.md b/CHANGELOG.md index cc7ba4559..18e67a6a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- add support for `lifecycle_rule` in gcs module - create `pubsub` service identity if service is enabled - support for creation of GKE Autopilot clusters - add support for CMEK keys in Data Foundation end to end example diff --git a/modules/gcs/README.md b/modules/gcs/README.md index ff27a5b63..095bb1059 100644 --- a/modules/gcs/README.md +++ b/modules/gcs/README.md @@ -60,6 +60,40 @@ module "bucket" { # tftest:modules=1:resources=2 ``` +### Example with lifecycle rule + +```hcl +module "bucket" { + source = "./modules/gcs" + project_id = "myproject" + prefix = "test" + name = "my-bucket" + + iam = { + "roles/storage.admin" = ["group:storage@example.com"] + } + + lifecycle_rule = { + action = { + type = "SetStorageClass" + storage_class = "STANDARD" + } + condition = { + age = 30 + created_before = null + with_state = null + matches_storage_class = null + num_newer_versions = null + custom_time_before = null + days_since_custom_time = null + days_since_noncurrent_time = null + noncurrent_time_before = null + } + } +} +# tftest:modules=1:resources=2 +``` + ## Variables @@ -72,6 +106,7 @@ module "bucket" { | *force_destroy* | Optional map to set force destroy keyed by name, defaults to false. | bool | | false | | *iam* | IAM bindings in {ROLE => [MEMBERS]} format. | map(list(string)) | | {} | | *labels* | Labels to be attached to all buckets. | map(string) | | {} | +| *lifecycle_rule* | Bucket lifecycle rule | object({...}) | | null | | *location* | Bucket location. | string | | EU | | *logging_config* | Bucket logging configuration. | object({...}) | | null | | *prefix* | Prefix used to generate the bucket name. | string | | null | diff --git a/modules/gcs/main.tf b/modules/gcs/main.tf index 0b86f770b..59cbb1350 100644 --- a/modules/gcs/main.tf +++ b/modules/gcs/main.tf @@ -71,6 +71,27 @@ resource "google_storage_bucket" "bucket" { max_age_seconds = max(3600, var.cors.max_age_seconds) } } + + dynamic lifecycle_rule { + for_each = var.lifecycle_rule == null ? [] : [""] + content { + action { + type = var.lifecycle_rule.action["type"] + storage_class = var.lifecycle_rule.action["storage_class"] + } + condition { + age = var.lifecycle_rule.condition["age"] + created_before = var.lifecycle_rule.condition["created_before"] + with_state = var.lifecycle_rule.condition["with_state"] + matches_storage_class = var.lifecycle_rule.condition["matches_storage_class"] + num_newer_versions = var.lifecycle_rule.condition["num_newer_versions"] + custom_time_before = var.lifecycle_rule.condition["custom_time_before"] + days_since_custom_time = var.lifecycle_rule.condition["days_since_custom_time"] + days_since_noncurrent_time = var.lifecycle_rule.condition["days_since_noncurrent_time"] + noncurrent_time_before = var.lifecycle_rule.condition["noncurrent_time_before"] + } + } + } } resource "google_storage_bucket_iam_binding" "bindings" { diff --git a/modules/gcs/variables.tf b/modules/gcs/variables.tf index 268acfb35..cfb5e573f 100644 --- a/modules/gcs/variables.tf +++ b/modules/gcs/variables.tf @@ -110,3 +110,25 @@ variable "cors" { }) default = null } + +variable "lifecycle_rule" { + description = "Bucket lifecycle rule" + type = object({ + action = object({ + type = string + storage_class = string + }) + condition = object({ + age = number + created_before = string + with_state = string + matches_storage_class = list(string) + num_newer_versions = string + custom_time_before = string + days_since_custom_time = string + days_since_noncurrent_time = string + noncurrent_time_before = string + }) + }) + default = null +} diff --git a/tests/modules/net-interconnect-attachment-direct/__init__.py b/tests/modules/net_interconnect_attachment_direct/__init__.py similarity index 100% rename from tests/modules/net-interconnect-attachment-direct/__init__.py rename to tests/modules/net_interconnect_attachment_direct/__init__.py diff --git a/tests/modules/net-interconnect-attachment-direct/fixture/main.tf b/tests/modules/net_interconnect_attachment_direct/fixture/main.tf similarity index 100% rename from tests/modules/net-interconnect-attachment-direct/fixture/main.tf rename to tests/modules/net_interconnect_attachment_direct/fixture/main.tf diff --git a/tests/modules/net-interconnect-attachment-direct/fixture/variables.tf b/tests/modules/net_interconnect_attachment_direct/fixture/variables.tf similarity index 100% rename from tests/modules/net-interconnect-attachment-direct/fixture/variables.tf rename to tests/modules/net_interconnect_attachment_direct/fixture/variables.tf diff --git a/tests/modules/net-interconnect-attachment-direct/test_plan.py b/tests/modules/net_interconnect_attachment_direct/test_plan.py similarity index 100% rename from tests/modules/net-interconnect-attachment-direct/test_plan.py rename to tests/modules/net_interconnect_attachment_direct/test_plan.py