Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <pre>object({<br> main_page_suffix = optional(string)<br> not_found_page = optional(string)<br> })</pre> | `{}` | no |
Expand Down
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions modules/simple_bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | <pre>object({<br> is_locked = optional(bool)<br> retention_period = number<br> })</pre> | `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 | <pre>object({<br> retention_duration_seconds = optional(number)<br> })</pre> | `{}` | 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 | <pre>object({<br> main_page_suffix = optional(string)<br> not_found_page = optional(string)<br> })</pre> | `{}` | no |

Expand Down
3 changes: 2 additions & 1 deletion modules/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ resource "google_storage_bucket" "bucket" {
}

autoclass {
enabled = var.autoclass
enabled = var.autoclass
terminal_storage_class = var.terminal_autoclass
}

hierarchical_namespace {
Expand Down
10 changes: 10 additions & 0 deletions modules/simple_bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we maintain a min TF compat with tf 1.3 we cannot use cross variable reference in validation rules (i.e checking var.autoclass) which was introduced in 1.9. If there is a validation error if this is set and autoclass is disabled could we perform a check before passing value to terminal_storage_class - something like lookup(var.autoclass..) ? lookup(var.terminal_autoclass...) : null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bharathkkb

The lookup during the assignment would be of no use as this is specifically to root out the wrong input (basically converting the string to an enum). Since it has to be compatible with v1.3 I will remove the autoclass check from the validation block.

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)
Expand Down