diff --git a/README.md b/README.md index f0fa3109..95247a8e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,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/main.tf b/main.tf
index 022f3d35..8808c117 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/README.md b/modules/simple_bucket/README.md
index 53dacfe4..6cdb4807 100644
--- a/modules/simple_bucket/README.md
+++ b/modules/simple_bucket/README.md
@@ -59,6 +59,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 b401bbdf..ecf845b4 100644
--- a/modules/simple_bucket/main.tf
+++ b/modules/simple_bucket/main.tf
@@ -34,7 +34,8 @@ resource "google_storage_bucket" "bucket" {
}
autoclass {
- enabled = var.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 949d4dbd..aabd52dd 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.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 3f2d5810..3deb61c5 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 = 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"
+ }
+}
+
variable "hierarchical_namespace" {
description = "Optional map of lowercase unprefixed bucket name => boolean, defaults to false."
type = map(bool)