From 6ffefd7ff30a02f90deb0a9053b8cae09c2a1b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20J=C3=BAnior=20do=20Nascimento=20Lima?= Date: Fri, 5 Feb 2021 16:43:39 -0300 Subject: [PATCH] Add cors option --- main.tf | 11 +++++++++++ variables.tf | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/main.tf b/main.tf index a8db957..5df2d30 100644 --- a/main.tf +++ b/main.tf @@ -12,6 +12,17 @@ resource "aws_s3_bucket" "s3_default" { force_destroy = var.force_destroy acl = var.acl + dynamic "cors_rule" { + for_each = var.cors_rule_inputs == null ? [] : var.cors_rule_inputs + + content { + allowed_headers = cors_rule.value.allowed_headers + allowed_methods = cors_rule.value.allowed_methods + allowed_origins = cors_rule.value.allowed_origins + expose_headers = cors_rule.value.expose_headers + } + } + versioning { enabled = var.versioning } diff --git a/variables.tf b/variables.tf index b938563..5baf418 100644 --- a/variables.tf +++ b/variables.tf @@ -207,4 +207,15 @@ variable "force_destroy" { type = bool default = false description = "A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable." +} + +variable "cors_rule_inputs" { + type = list(object({ + allowed_headers = list(string) + allowed_methods = list(string) + allowed_origins = list(string) + expose_headers = list(string) + })) + default = null + description = "Specifies the allowed headers, methods, origins and exposed headers when using CORS on this bucket" } \ No newline at end of file