Skip to content

Commit

Permalink
feat: Support for CORS in simple bucket (#128)
Browse files Browse the repository at this point in the history
* Add support for cors in simple bucket

* fix typo

* use any type + fmt + docs

* iterate over all cors settings instead of 1

* fix readme
  • Loading branch information
mkjmdski authored Sep 10, 2021
1 parent a0982c9 commit e6559e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/simple_bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Functional examples are included in the
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| 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 |
| 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
10 changes: 10 additions & 0 deletions modules/simple_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ resource "google_storage_bucket" "bucket" {
}
}

dynamic "cors" {
for_each = var.cors == null ? [] : var.cors
content {
origin = lookup(cors.value, "origin", null)
method = lookup(cors.value, "method", null)
response_header = lookup(cors.value, "response_header", null)
max_age_seconds = lookup(cors.value, "max_age_seconds", null)
}
}

dynamic "lifecycle_rule" {
for_each = var.lifecycle_rules
content {
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 @@ -78,6 +78,12 @@ variable "retention_policy" {
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
default = []
}

variable "encryption" {
description = "A Cloud KMS key that will be used to encrypt objects inserted into this bucket"
type = object({
Expand Down

0 comments on commit e6559e9

Please sign in to comment.