Skip to content

Commit

Permalink
feat: Added support for custom placement config for Cloud Storage Buc…
Browse files Browse the repository at this point in the history
…ket (#160)
  • Loading branch information
cgsyam authored Jun 20, 2023
1 parent 18de12b commit f896ebe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ so that all dependencies are met.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| data\_locations | Configuration of the bucket's custom location in a dual-region bucket setup. If the bucket is designated a single or multi-region, then the variable will be null. Note: If any of the data\_locations changes, it will recreate the bucket. | `list(string)` | `null` | no |
| force\_destroy | When deleting a bucket, this boolean option will delete all contained objects. | `bool` | `false` | no |
| kms\_key\_name | ID of a Cloud KMS key that will be used to encrypt objects inserted into this bucket. Automatic Google Cloud Storage service account for the bucket's project requires access to this encryption key. | `string` | `null` | no |
| lifecycle\_rules | List of lifecycle rules to configure. Format is the same as described in provider documentation https://www.terraform.io/docs/providers/google/r/storage_bucket.html#lifecycle_rule except condition.matches\_storage\_class should be a comma delimited string. | <pre>set(object({<br> # Object with keys:<br> # - type - The type of the action of this Lifecycle Rule. Supported values: Delete and SetStorageClass.<br> # - storage_class - (Required if action type is SetStorageClass) The target Storage Class of objects affected by this Lifecycle Rule.<br> action = map(string)<br><br> # Object with keys:<br> # - age - (Optional) Minimum age of an object in days to satisfy this condition.<br> # - created_before - (Optional) Creation date of an object in RFC 3339 (e.g. 2017-06-13) to satisfy this condition.<br> # - with_state - (Optional) Match to live and/or archived objects. Supported values include: "LIVE", "ARCHIVED", "ANY".<br> # - matches_storage_class - (Optional) Comma delimited string for storage class of objects to satisfy this condition. Supported values include: MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, STANDARD, DURABLE_REDUCED_AVAILABILITY.<br> # - num_newer_versions - (Optional) Relevant only for versioned objects. The number of newer versions of an object to satisfy this condition.<br> # - days_since_custom_time - (Optional) The number of days from the Custom-Time metadata attribute after which this condition becomes true.<br> condition = map(string)<br> }))</pre> | `[]` | no |
Expand Down
7 changes: 7 additions & 0 deletions modules/storage/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ resource "google_storage_bucket" "bucket" {
default_kms_key_name = var.kms_key_name
}
}

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

#--------------------------------#
Expand Down
6 changes: 6 additions & 0 deletions modules/storage/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ variable "kms_key_name" {
type = string
default = null
}

variable "data_locations" {
description = "Configuration of the bucket's custom location in a dual-region bucket setup. If the bucket is designated a single or multi-region, then the variable will be null. Note: If any of the data_locations changes, it will recreate the bucket."
type = list(string)
default = null
}
2 changes: 1 addition & 1 deletion modules/storage/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 3.53, < 5.0"
version = ">= 4.40, < 5.0"
}
}

Expand Down

0 comments on commit f896ebe

Please sign in to comment.