Skip to content

Commit

Permalink
feat: support a list of rules instead of a single rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalarrs Topham committed Aug 5, 2020
1 parent 0da340b commit c591b95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,16 @@ 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(object({
allowed_headers = list(string)
allowed_methods = list(string)
allowed_origins = list(string)
expose_headers = list(string)
max_age_seconds = number
}))
default = []
}

variable "versioning" {
Expand Down

0 comments on commit c591b95

Please sign in to comment.