Skip to content

Commit

Permalink
feat!: add support for custom_placement_config (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnksv authored Mar 21, 2023
1 parent 608dd57 commit a0bbdbd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Functional examples are included in the
| bucket\_viewers | Map of lowercase unprefixed name => comma-delimited IAM-style per-bucket viewers. | `map(string)` | `{}` | no |
| cors | Set of maps of mixed type attributes for CORS values. See appropriate attribute types here: https://www.terraform.io/docs/providers/google/r/storage_bucket.html#cors | `set(any)` | `[]` | no |
| creators | IAM-style members who will be granted roles/storage.objectCreators on all buckets. | `list(string)` | `[]` | no |
| custom\_placement\_config | Map of lowercase unprefixed name => custom placement config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket#custom_placement_config | `any` | `{}` | no |
| default\_event\_based\_hold | Enable event based hold to new objects added to specific bucket. Defaults to false. Map of lowercase unprefixed name => boolean | `map(bool)` | `{}` | no |
| encryption\_key\_names | Optional map of lowercase unprefixed name => string, empty strings are ignored. | `map(string)` | `{}` | no |
| folders | Map of lowercase unprefixed name => list of top level folder objects. | `map(list(string))` | `{}` | no |
Expand Down
1 change: 1 addition & 0 deletions examples/multiple_buckets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module "cloud_storage" {
"one" = true
"two" = false
}

folders = {
"two" = ["dev", "prod"]
}
Expand Down
6 changes: 5 additions & 1 deletion examples/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module "bucket" {

name = "${var.project_id}-bucket"
project_id = var.project_id
location = "us-east1"
location = "us"

lifecycle_rules = [{
action = {
Expand All @@ -32,6 +32,10 @@ module "bucket" {
}
}]

custom_placement_config = {
data_locations : ["US-EAST4", "US-WEST1"]
}

iam_members = [{
role = "roles/storage.objectViewer"
member = "group:[email protected]"
Expand Down
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ resource "google_storage_bucket" "buckets" {
}
}

dynamic "custom_placement_config" {
for_each = lookup(var.custom_placement_config, each.value, {}) != {} ? [var.custom_placement_config[each.value]] : []
content {
data_locations = lookup(custom_placement_config.value, "data_locations", null)
}
}

dynamic "lifecycle_rule" {
for_each = setunion(var.lifecycle_rules, lookup(var.bucket_lifecycle_rules, each.value, toset([])))
content {
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 @@ -40,6 +40,7 @@ Functional examples are included in the
|------|-------------|------|---------|:--------:|
| 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 |
| encryption | A Cloud KMS key that will be used to encrypt objects inserted into this bucket | <pre>object({<br> default_kms_key_name = string<br> })</pre> | `null` | no |
| force\_destroy | When deleting a bucket, this boolean option will delete all contained objects. If false, Terraform will fail to delete buckets which contain objects. | `bool` | `false` | no |
| iam\_members | The list of IAM members to grant permissions on the bucket. | <pre>list(object({<br> role = string<br> member = string<br> }))</pre> | `[]` | no |
Expand Down
7 changes: 7 additions & 0 deletions modules/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ resource "google_storage_bucket" "bucket" {
}
}

dynamic "custom_placement_config" {
for_each = var.custom_placement_config == null ? [] : [var.custom_placement_config]
content {
data_locations = var.custom_placement_config.data_locations
}
}

dynamic "lifecycle_rule" {
for_each = var.lifecycle_rules
content {
Expand Down
8 changes: 8 additions & 0 deletions modules/simple_bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ variable "retention_policy" {
default = null
}

variable "custom_placement_config" {
description = "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."
type = object({
data_locations = list(string)
})
default = null
}

variable "cors" {
description = "Configuration of CORS for bucket with structure as defined in https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket#cors."
type = any
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ variable "retention_policy" {
description = "Map of retention policy values. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket#retention_policy"
}

variable "custom_placement_config" {
type = any
default = {}
description = "Map of lowercase unprefixed name => custom placement config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket#custom_placement_config"
}

variable "logging" {
description = "Map of lowercase unprefixed name => bucket logging config object. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#logging"
type = any
Expand Down

0 comments on commit a0bbdbd

Please sign in to comment.