Skip to content

Commit 8aea781

Browse files
jjungnickelmaximmi
andauthored
Add the ability to specify cors-rules (#16)
* Add the ability to specify cors-rules * Update readme, description Co-authored-by: Maxim Mironenko <[email protected]>
1 parent 31f7f40 commit 8aea781

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Available targets:
128128
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no |
129129
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `<list>` | no |
130130
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
131+
| cors_rule_inputs | Specifies the allowed headers, methods, origins and exposed headers when using CORS on this bucket | object | `null` | no |
131132
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
132133
| enable_glacier_transition | Enables the transition to AWS Glacier which can cause unnecessary costs for huge amount of small files | bool | `true` | no |
133134
| enable_standard_ia_transition | Enables the transition to STANDARD_IA | bool | `false` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | bool | `false` | no |
88
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list(string) | `<list>` | no |
99
| attributes | Additional attributes (e.g. `1`) | list(string) | `<list>` | no |
10+
| cors_rule_inputs | Specifies the allowed headers, methods, origins and exposed headers when using CORS on this bucket | object | `null` | no |
1011
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | string | `-` | no |
1112
| enable_glacier_transition | Enables the transition to AWS Glacier which can cause unnecessary costs for huge amount of small files | bool | `true` | no |
1213
| enable_standard_ia_transition | Enables the transition to STANDARD_IA | bool | `false` | no |

main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ resource "aws_s3_bucket" "default" {
7878
}
7979

8080
tags = module.label.tags
81+
dynamic "cors_rule" {
82+
for_each = var.cors_rule_inputs == null ? [] : var.cors_rule_inputs
83+
84+
content {
85+
allowed_headers = cors_rule.value.allowed_headers
86+
allowed_methods = cors_rule.value.allowed_methods
87+
allowed_origins = cors_rule.value.allowed_origins
88+
expose_headers = cors_rule.value.expose_headers
89+
max_age_seconds = cors_rule.value.max_age_seconds
90+
}
91+
}
92+
8193
}
8294

8395
module "s3_user" {

variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ variable "noncurrent_version_expiration_days" {
130130
description = "Specifies when noncurrent object versions expire"
131131
}
132132

133+
variable "cors_rule_inputs" {
134+
type = list(object({
135+
allowed_headers = list(string)
136+
allowed_methods = list(string)
137+
allowed_origins = list(string)
138+
expose_headers = list(string)
139+
max_age_seconds = number
140+
}))
141+
default = null
142+
143+
description = "Specifies the allowed headers, methods, origins and exposed headers when using CORS on this bucket"
144+
}
145+
133146
variable "standard_transition_days" {
134147
type = number
135148
default = 30
@@ -171,4 +184,3 @@ variable "lifecycle_tags" {
171184
description = "Tags filter. Used to manage object lifecycle events"
172185
default = {}
173186
}
174-

0 commit comments

Comments
 (0)