From 2d7b4ef7b334ec73aca64161e1625cac7797ab6f Mon Sep 17 00:00:00 2001 From: snskArora Date: Sat, 21 Jun 2025 15:23:28 +0530 Subject: [PATCH 1/4] feat: Adding terminal autoclass variable for simple and multiple bucket --- main.tf | 5 +++++ modules/simple_bucket/main.tf | 1 + modules/simple_bucket/variables.tf | 10 ++++++++++ variables.tf | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/main.tf b/main.tf index 345fd3b..ab36130 100644 --- a/main.tf +++ b/main.tf @@ -75,6 +75,11 @@ resource "google_storage_bucket" "buckets" { lower(each.value), false, ) + terminal_storage_class = lookup( + var.terminal_autoclass, + lower(each.value), + "NEARLINE" + ) } hierarchical_namespace { enabled = lookup( diff --git a/modules/simple_bucket/main.tf b/modules/simple_bucket/main.tf index 915ad20..80160f3 100644 --- a/modules/simple_bucket/main.tf +++ b/modules/simple_bucket/main.tf @@ -35,6 +35,7 @@ resource "google_storage_bucket" "bucket" { autoclass { enabled = var.autoclass + terminal_storage_class = var.terminal_autoclass } hierarchical_namespace { diff --git a/modules/simple_bucket/variables.tf b/modules/simple_bucket/variables.tf index 227ad69..ae06a53 100644 --- a/modules/simple_bucket/variables.tf +++ b/modules/simple_bucket/variables.tf @@ -75,6 +75,16 @@ variable "autoclass" { default = false } +variable "terminal_autoclass" { + description = "The storage class that objects in the bucket eventually transition to if they are not read for a certain length of time. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true" + type = string + default = "NEARLINE" + validation { + condition = var.autoclass == false || var.terminal_autoclass == "NEARLINE" || var.terminal_autoclass == "ARCHIVE" + error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" + } +} + variable "hierarchical_namespace" { description = "When set to true, hierarchical namespace is enable for this bucket." type = bool diff --git a/variables.tf b/variables.tf index 1a8b00b..d1b5a10 100644 --- a/variables.tf +++ b/variables.tf @@ -66,6 +66,16 @@ variable "autoclass" { default = {} } +variable "terminal_autoclass" { + description = "Optional map of storage class that objects in the bucket eventually transitions to. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true. bucket_name => value, defaults to NEARLINE" + type = map(string) + default = {} + validation { + condition = alltrue([ for _, v in var.terminal_autoclass : var.autoclass == false || v == "NEARLINE" || v == "ARCHIVE"]) + error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" + } +} + variable "hierarchical_namespace" { description = "Optional map of lowercase unprefixed bucket name => boolean, defaults to false." type = map(bool) From b9c648de35f986b696d5a98838d50b5c1929b34c Mon Sep 17 00:00:00 2001 From: snskArora Date: Sat, 21 Jun 2025 15:36:40 +0530 Subject: [PATCH 2/4] Updating readme and linting --- README.md | 1 + modules/simple_bucket/README.md | 1 + modules/simple_bucket/main.tf | 2 +- modules/simple_bucket/variables.tf | 6 +++--- variables.tf | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3380371..b57227b 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Functional examples are included in the | soft\_delete\_policy | Soft delete policies to apply. Map of lowercase unprefixed name => soft delete policy. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#nested_soft_delete_policy | `map(any)` | `{}` | no | | storage\_admins | IAM-style members who will be granted roles/storage.admin on all buckets. | `list(string)` | `[]` | no | | storage\_class | Bucket storage class. | `string` | `"STANDARD"` | no | +| terminal\_autoclass | Optional map of storage class that objects in the bucket eventually transitions to. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true. bucket\_name => value, defaults to NEARLINE | `map(string)` | `{}` | no | | versioning | Optional map of lowercase unprefixed name => boolean, defaults to false. | `map(bool)` | `{}` | no | | viewers | IAM-style members who will be granted roles/storage.objectViewer on all buckets. | `list(string)` | `[]` | no | | website | Map of website values. Supported attributes: main\_page\_suffix, not\_found\_page |
object({
main_page_suffix = optional(string)
not_found_page = optional(string)
})
| `{}` | no | diff --git a/modules/simple_bucket/README.md b/modules/simple_bucket/README.md index c9e0d18..86510b2 100644 --- a/modules/simple_bucket/README.md +++ b/modules/simple_bucket/README.md @@ -58,6 +58,7 @@ Functional examples are included in the | retention\_policy | Configuration of the bucket's data retention policy for how long objects in the bucket should be retained. |
object({
is_locked = optional(bool)
retention_period = number
})
| `null` | no | | soft\_delete\_policy | Soft delete policies to apply. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#nested_soft_delete_policy |
object({
retention_duration_seconds = optional(number)
})
| `{}` | no | | storage\_class | The Storage Class of the new bucket. | `string` | `null` | no | +| terminal\_autoclass | The storage class that objects in the bucket eventually transition to if they are not read for a certain length of time. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true | `string` | `"NEARLINE"` | no | | versioning | While set to true, versioning is fully enabled for this bucket. | `bool` | `true` | no | | website | Map of website values. Supported attributes: main\_page\_suffix, not\_found\_page |
object({
main_page_suffix = optional(string)
not_found_page = optional(string)
})
| `{}` | no | diff --git a/modules/simple_bucket/main.tf b/modules/simple_bucket/main.tf index 80160f3..e38dac7 100644 --- a/modules/simple_bucket/main.tf +++ b/modules/simple_bucket/main.tf @@ -34,7 +34,7 @@ resource "google_storage_bucket" "bucket" { } autoclass { - enabled = var.autoclass + enabled = var.autoclass terminal_storage_class = var.terminal_autoclass } diff --git a/modules/simple_bucket/variables.tf b/modules/simple_bucket/variables.tf index ae06a53..1bae3c4 100644 --- a/modules/simple_bucket/variables.tf +++ b/modules/simple_bucket/variables.tf @@ -77,10 +77,10 @@ variable "autoclass" { variable "terminal_autoclass" { description = "The storage class that objects in the bucket eventually transition to if they are not read for a certain length of time. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true" - type = string - default = "NEARLINE" + type = string + default = "NEARLINE" validation { - condition = var.autoclass == false || var.terminal_autoclass == "NEARLINE" || var.terminal_autoclass == "ARCHIVE" + condition = var.autoclass == false || var.terminal_autoclass == "NEARLINE" || var.terminal_autoclass == "ARCHIVE" error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" } } diff --git a/variables.tf b/variables.tf index d1b5a10..54d1025 100644 --- a/variables.tf +++ b/variables.tf @@ -68,10 +68,10 @@ variable "autoclass" { variable "terminal_autoclass" { description = "Optional map of storage class that objects in the bucket eventually transitions to. Supported values include: NEARLINE, ARCHIVE. Only used if autoclass is set as true. bucket_name => value, defaults to NEARLINE" - type = map(string) - default = {} + type = map(string) + default = {} validation { - condition = alltrue([ for _, v in var.terminal_autoclass : var.autoclass == false || v == "NEARLINE" || v == "ARCHIVE"]) + condition = alltrue([for _, v in var.terminal_autoclass : var.autoclass == false || v == "NEARLINE" || v == "ARCHIVE"]) error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" } } From 68218b6ae326347b5344c6985d301f56e04df153 Mon Sep 17 00:00:00 2001 From: Sunny <55059942+snskArora@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:05:53 +0530 Subject: [PATCH 3/4] Update variables.tf --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 54d1025..d312181 100644 --- a/variables.tf +++ b/variables.tf @@ -71,7 +71,7 @@ variable "terminal_autoclass" { type = map(string) default = {} validation { - condition = alltrue([for _, v in var.terminal_autoclass : var.autoclass == false || v == "NEARLINE" || v == "ARCHIVE"]) + condition = var.terminal_autoclass == {} || alltrue([for _, v in var.terminal_autoclass : v == "NEARLINE" || v == "ARCHIVE"]) error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" } } From 52c58be7afb94d8fd4e7ca18f1b4c8d7773d4792 Mon Sep 17 00:00:00 2001 From: Sunny <55059942+snskArora@users.noreply.github.com> Date: Sun, 10 Aug 2025 19:06:34 +0530 Subject: [PATCH 4/4] Update variables.tf --- modules/simple_bucket/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/simple_bucket/variables.tf b/modules/simple_bucket/variables.tf index 1bae3c4..d2b0938 100644 --- a/modules/simple_bucket/variables.tf +++ b/modules/simple_bucket/variables.tf @@ -80,7 +80,7 @@ variable "terminal_autoclass" { type = string default = "NEARLINE" validation { - condition = var.autoclass == false || var.terminal_autoclass == "NEARLINE" || var.terminal_autoclass == "ARCHIVE" + condition = var.terminal_autoclass == "NEARLINE" || var.terminal_autoclass == "ARCHIVE" error_message = "Acceptable value for terminal_autoclass is NEARLINE or ARCHIVE" } }