Skip to content

Commit 69dafb3

Browse files
authored
feat: Add support for cors and website config in variables (#63)
1 parent 0fa0689 commit 69dafb3

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Functional examples are included in the
5151
| bucket\_creators | Map of lowercase unprefixed name => comma-delimited IAM-style bucket creators. | map | `<map>` | no |
5252
| bucket\_policy\_only | Disable ad-hoc ACLs on specified buckets. Defaults to true. Map of lowercase unprefixed name => boolean | map | `<map>` | no |
5353
| bucket\_viewers | Map of lowercase unprefixed name => comma-delimited IAM-style bucket viewers. | map | `<map>` | no |
54+
| cors | Map 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 | any | `<map>` | no |
5455
| creators | IAM-style members who will be granted roles/storage.objectCreators on all buckets. | list(string) | `<list>` | no |
5556
| encryption\_key\_names | Optional map of lowercase unprefixed name => string, empty strings are ignored. | map | `<map>` | no |
5657
| folders | Map of lowercase unprefixed name => list of top level folder objects. | map | `<map>` | no |
@@ -67,6 +68,7 @@ Functional examples are included in the
6768
| storage\_class | Bucket storage class. | string | `"MULTI_REGIONAL"` | no |
6869
| versioning | Optional map of lowercase unprefixed name => boolean, defaults to false. | map | `<map>` | no |
6970
| viewers | IAM-style members who will be granted roles/storage.objectViewer on all buckets. | list(string) | `<list>` | no |
71+
| website | Map of website values. Supported attributes: main_page_suffix, not_found_page | any | `<map>` | no |
7072

7173
## Outputs
7274

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ resource "google_storage_bucket" "buckets" {
6767
)
6868
}
6969
}
70+
dynamic "cors" {
71+
for_each = lookup(var.cors, element(var.names, count.index), {}) != {} ? { v = lookup(var.cors, element(var.names, count.index)) } : {}
72+
content {
73+
origin = lookup(cors.value, "origin", null)
74+
method = lookup(cors.value, "method", null)
75+
response_header = lookup(cors.value, "response_header", null)
76+
max_age_seconds = lookup(cors.value, "max_age_seconds", null)
77+
}
78+
}
79+
dynamic "website" {
80+
for_each = lookup(var.website, element(var.names, count.index), {}) != {} ? { v = lookup(var.website, element(var.names, count.index)) } : {}
81+
content {
82+
main_page_suffix = lookup(website.value, "main_page_suffix", null)
83+
not_found_page = lookup(website.value, "not_found_page", null)
84+
}
85+
}
86+
7087
dynamic "lifecycle_rule" {
7188
for_each = var.lifecycle_rules
7289
content {

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,15 @@ variable "lifecycle_rules" {
151151
description = "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."
152152
default = []
153153
}
154+
155+
variable "cors" {
156+
description = "Map 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"
157+
type = any
158+
default = {}
159+
}
160+
161+
variable "website" {
162+
type = any
163+
default = {}
164+
description = "Map of website values. Supported attributes: main_page_suffix, not_found_page"
165+
}

0 commit comments

Comments
 (0)