Skip to content

Commit

Permalink
feat: Add support for cors and website config in variables (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkatsovich authored May 26, 2020
1 parent 0fa0689 commit 69dafb3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Functional examples are included in the
| bucket\_creators | Map of lowercase unprefixed name => comma-delimited IAM-style bucket creators. | map | `<map>` | no |
| bucket\_policy\_only | Disable ad-hoc ACLs on specified buckets. Defaults to true. Map of lowercase unprefixed name => boolean | map | `<map>` | no |
| bucket\_viewers | Map of lowercase unprefixed name => comma-delimited IAM-style bucket viewers. | map | `<map>` | no |
| 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 |
| creators | IAM-style members who will be granted roles/storage.objectCreators on all buckets. | list(string) | `<list>` | no |
| encryption\_key\_names | Optional map of lowercase unprefixed name => string, empty strings are ignored. | map | `<map>` | no |
| folders | Map of lowercase unprefixed name => list of top level folder objects. | map | `<map>` | no |
Expand All @@ -67,6 +68,7 @@ Functional examples are included in the
| storage\_class | Bucket storage class. | string | `"MULTI_REGIONAL"` | no |
| versioning | Optional map of lowercase unprefixed name => boolean, defaults to false. | map | `<map>` | no |
| viewers | IAM-style members who will be granted roles/storage.objectViewer on all buckets. | list(string) | `<list>` | no |
| website | Map of website values. Supported attributes: main_page_suffix, not_found_page | any | `<map>` | no |

## Outputs

Expand Down
17 changes: 17 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ resource "google_storage_bucket" "buckets" {
)
}
}
dynamic "cors" {
for_each = lookup(var.cors, element(var.names, count.index), {}) != {} ? { v = lookup(var.cors, element(var.names, count.index)) } : {}
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 "website" {
for_each = lookup(var.website, element(var.names, count.index), {}) != {} ? { v = lookup(var.website, element(var.names, count.index)) } : {}
content {
main_page_suffix = lookup(website.value, "main_page_suffix", null)
not_found_page = lookup(website.value, "not_found_page", null)
}
}

dynamic "lifecycle_rule" {
for_each = var.lifecycle_rules
content {
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,15 @@ variable "lifecycle_rules" {
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."
default = []
}

variable "cors" {
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"
type = any
default = {}
}

variable "website" {
type = any
default = {}
description = "Map of website values. Supported attributes: main_page_suffix, not_found_page"
}

0 comments on commit 69dafb3

Please sign in to comment.