Add support for lifecycle_rule in gcs module (#288) (#289)

* Add support for lifecycle_rule in gcs module (#288)

Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>

* fix docs

* rename unrelated interconnect module tests

* fix doc example test

Co-authored-by: iury <1934268+IuryAlves@users.noreply.github.com>
This commit is contained in:
Ludovico Magnocavallo 2021-07-30 12:07:17 +02:00 committed by GitHub
parent 598e4f5ee1
commit 202892b344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 0 deletions

View File

@ -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

View File

@ -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
```
<!-- BEGIN TFDOC -->
## Variables
@ -72,6 +106,7 @@ module "bucket" {
| *force_destroy* | Optional map to set force destroy keyed by name, defaults to false. | <code title="">bool</code> | | <code title="">false</code> |
| *iam* | IAM bindings in {ROLE => [MEMBERS]} format. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *labels* | Labels to be attached to all buckets. | <code title="map&#40;string&#41;">map(string)</code> | | <code title="">{}</code> |
| *lifecycle_rule* | Bucket lifecycle rule | <code title="object&#40;&#123;&#10;action &#61; object&#40;&#123;&#10;type &#61; string&#10;storage_class &#61; string&#10;&#125;&#41;&#10;condition &#61; object&#40;&#123;&#10;age &#61; number&#10;created_before &#61; string&#10;with_state &#61; string&#10;matches_storage_class &#61; list&#40;string&#41;&#10;num_newer_versions &#61; string&#10;custom_time_before &#61; string&#10;days_since_custom_time &#61; string&#10;days_since_noncurrent_time &#61; string&#10;noncurrent_time_before &#61; string&#10;&#125;&#41;&#10;&#125;&#41;">object({...})</code> | | <code title="">null</code> |
| *location* | Bucket location. | <code title="">string</code> | | <code title="">EU</code> |
| *logging_config* | Bucket logging configuration. | <code title="object&#40;&#123;&#10;log_bucket &#61; string&#10;log_object_prefix &#61; string&#10;&#125;&#41;">object({...})</code> | | <code title="">null</code> |
| *prefix* | Prefix used to generate the bucket name. | <code title="">string</code> | | <code title="">null</code> |

View File

@ -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" {

View File

@ -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
}