From 446d754957a350e01e7d7ca74f838dce2400ab38 Mon Sep 17 00:00:00 2001 From: Kalarrs Topham Date: Sun, 9 Aug 2020 18:52:31 -0700 Subject: [PATCH] feat: support a list of rules instead of a single rule --- README.md | 2 +- examples/complete/main.tf | 4 ++-- main.tf | 2 +- variables.tf | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f4a69c71..3517e51b 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ module "s3_bucket" { | 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\_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\_rules | List containing rules for Cross-Origin Resource Sharing. | `any` | `{}` | 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 | | ignore\_public\_acls | Whether Amazon S3 should ignore public ACLs for this bucket. | `bool` | `false` | no | diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 01c589a0..a607be2f 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -92,13 +92,13 @@ module "s3_bucket" { target_prefix = "log/" } - cors_rule = { + cors_rules = [{ allowed_methods = ["PUT", "POST"] allowed_origins = ["https://modules.tf", "https://terraform-aws-modules.modules.tf"] allowed_headers = ["*"] expose_headers = ["ETag"] max_age_seconds = 3000 - } + }] lifecycle_rule = [ { diff --git a/main.tf b/main.tf index 85181ab1..57546c39 100644 --- a/main.tf +++ b/main.tf @@ -22,7 +22,7 @@ resource "aws_s3_bucket" "this" { } dynamic "cors_rule" { - for_each = length(keys(var.cors_rule)) == 0 ? [] : [var.cors_rule] + for_each = var.cors_rules content { allowed_methods = cors_rule.value.allowed_methods diff --git a/variables.tf b/variables.tf index f6c3c159..e1b94f10 100644 --- a/variables.tf +++ b/variables.tf @@ -82,10 +82,10 @@ variable "website" { default = {} } -variable "cors_rule" { - description = "Map containing a rule of Cross-Origin Resource Sharing." - type = any # should be `map`, but it produces an error "all map elements must have the same type" - default = {} +variable "cors_rules" { + description = "List containing rules for Cross-Origin Resource Sharing." + type = list(any) + default = [] } variable "versioning" {