Skip to content

Commit

Permalink
feat(TPG >= 4.46)!: adds support to autoclass (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoiury authored Aug 7, 2023
1 parent 89ab90b commit 52eaa5a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Functional examples are included in the
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| admins | IAM-style members who will be granted roles/storage.objectAdmin on all buckets. | `list(string)` | `[]` | no |
| autoclass | Optional map of lowercase unprefixed bucket name => boolean, defaults to false. | `map(bool)` | `{}` | no |
| bucket\_admins | Map of lowercase unprefixed name => comma-delimited IAM-style per-bucket admins. | `map(string)` | `{}` | no |
| bucket\_creators | Map of lowercase unprefixed name => comma-delimited IAM-style per-bucket creators. | `map(string)` | `{}` | no |
| bucket\_hmac\_key\_admins | Map of lowercase unprefixed name => comma-delimited IAM-style per-bucket HMAC Key admins. | `map(string)` | `{}` | no |
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ module "bucket" {
role = "roles/storage.objectViewer"
member = "group:test-gcp-ops@test.blueprints.joonix.net"
}]

autoclass = true
}
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ resource "google_storage_bucket" "buckets" {
lower(each.value),
false,
)
autoclass {
enabled = lookup(
var.autoclass,
lower(each.value),
false,
)
}
# Having a permanent encryption block with default_kms_key_name = "" works but results in terraform applying a change every run
# There is no enabled = false attribute available to ask terraform to ignore the block
dynamic "encryption" {
Expand Down
5 changes: 5 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ spec:
type: map(any)
default: {}
required: false
- name: autoclass
description: Optional map of lowercase unprefixed bucket name => boolean, defaults to false.
type: map(bool)
default: {}
required: false
outputs:
- name: bucket
description: Bucket resource (for single use).
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 @@ -38,6 +38,7 @@ Functional examples are included in the

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| autoclass | While set to true, autoclass is enabled for this bucket. | `bool` | `false` | no |
| bucket\_policy\_only | Enables Bucket Policy Only access to a bucket. | `bool` | `true` | no |
| cors | Configuration of CORS for bucket with structure as defined in https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket#cors. | `any` | `[]` | no |
| custom\_placement\_config | Configuration of the bucket's custom location in a dual-region bucket setup. If the bucket is designated a single or multi-region, the variable are null. | <pre>object({<br> data_locations = list(string)<br> })</pre> | `null` | no |
Expand Down
4 changes: 4 additions & 0 deletions modules/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ resource "google_storage_bucket" "bucket" {
enabled = var.versioning
}

autoclass {
enabled = var.autoclass
}

dynamic "retention_policy" {
for_each = var.retention_policy == null ? [] : [var.retention_policy]
content {
Expand Down
5 changes: 5 additions & 0 deletions modules/simple_bucket/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ spec:
type: map(any)
default: {}
required: false
- name: autoclass
description: While set to true, autoclass is enabled for this bucket.
type: bool
default: false
required: false
outputs:
- name: bucket
description: The created storage bucket
Expand Down
6 changes: 6 additions & 0 deletions modules/simple_bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ variable "versioning" {
default = true
}

variable "autoclass" {
description = "While set to true, autoclass is enabled for this bucket."
type = bool
default = false
}

variable "force_destroy" {
description = "When deleting a bucket, this boolean option will delete all contained objects. If false, Terraform will fail to delete buckets which contain objects."
type = bool
Expand Down
2 changes: 1 addition & 1 deletion modules/simple_bucket/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 4.42, < 5.0"
version = ">= 4.46, < 5.0"
}
}

Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ variable "versioning" {
default = {}
}

variable "autoclass" {
description = "Optional map of lowercase unprefixed bucket name => boolean, defaults to false."
type = map(bool)
default = {}
}

variable "encryption_key_names" {
description = "Optional map of lowercase unprefixed name => string, empty strings are ignored."
type = map(string)
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 4.42, < 5.0"
version = ">= 4.46, < 5.0"
}

random = {
Expand Down

0 comments on commit 52eaa5a

Please sign in to comment.