Commit 4e1d7ab0 authored by Kalarrs Topham's avatar Kalarrs Topham Committed by GitHub

feat: support a list of CORS rules instead of a single rule (#40)

parent 4bc5b4d4
...@@ -106,7 +106,7 @@ module "s3_bucket" { ...@@ -106,7 +106,7 @@ module "s3_bucket" {
| block\_public\_policy | Whether Amazon S3 should block public bucket policies for this bucket. | `bool` | `false` | no | | block\_public\_policy | Whether Amazon S3 should block public bucket policies for this bucket. | `bool` | `false` | no |
| bucket | (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no | | bucket | (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no |
| bucket\_prefix | (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix. Conflicts with bucket. | `string` | `null` | no | | bucket\_prefix | (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix. Conflicts with bucket. | `string` | `null` | no |
| cors\_rule | Map containing a rule of Cross-Origin Resource Sharing. | `any` | `{}` | no | | cors\_rule | List of maps containing rules for Cross-Origin Resource Sharing. | `list(any)` | `[]` | no |
| create\_bucket | Controls if S3 bucket should be created | `bool` | `true` | no | | create\_bucket | Controls if S3 bucket should be created | `bool` | `true` | no |
| force\_destroy | (Optional, Default:false ) 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. | `bool` | `false` | no | | force\_destroy | (Optional, Default:false ) 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. | `bool` | `false` | no |
| ignore\_public\_acls | Whether Amazon S3 should ignore public ACLs for this bucket. | `bool` | `false` | no | | ignore\_public\_acls | Whether Amazon S3 should ignore public ACLs for this bucket. | `bool` | `false` | no |
......
...@@ -92,13 +92,21 @@ module "s3_bucket" { ...@@ -92,13 +92,21 @@ module "s3_bucket" {
target_prefix = "log/" target_prefix = "log/"
} }
cors_rule = { cors_rule = [
{
allowed_methods = ["PUT", "POST"] allowed_methods = ["PUT", "POST"]
allowed_origins = ["https://modules.tf", "https://terraform-aws-modules.modules.tf"] allowed_origins = ["https://modules.tf", "https://terraform-aws-modules.modules.tf"]
allowed_headers = ["*"] allowed_headers = ["*"]
expose_headers = ["ETag"] expose_headers = ["ETag"]
max_age_seconds = 3000 max_age_seconds = 3000
}, {
allowed_methods = ["PUT"]
allowed_origins = ["https://example.com"]
allowed_headers = ["*"]
expose_headers = ["ETag"]
max_age_seconds = 3000
} }
]
lifecycle_rule = [ lifecycle_rule = [
{ {
......
...@@ -21,7 +21,7 @@ resource "aws_s3_bucket" "this" { ...@@ -21,7 +21,7 @@ resource "aws_s3_bucket" "this" {
} }
dynamic "cors_rule" { dynamic "cors_rule" {
for_each = length(keys(var.cors_rule)) == 0 ? [] : [var.cors_rule] for_each = var.cors_rule
content { content {
allowed_methods = cors_rule.value.allowed_methods allowed_methods = cors_rule.value.allowed_methods
......
...@@ -77,9 +77,9 @@ variable "website" { ...@@ -77,9 +77,9 @@ variable "website" {
} }
variable "cors_rule" { variable "cors_rule" {
description = "Map containing a rule of Cross-Origin Resource Sharing." description = "List of maps containing rules for Cross-Origin Resource Sharing."
type = any # should be `map`, but it produces an error "all map elements must have the same type" type = list(any)
default = {} default = []
} }
variable "versioning" { variable "versioning" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment