File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ resource "aws_s3_bucket" "bucket" {
20
20
policy = data. aws_iam_policy_document . bucket_policy . json
21
21
22
22
versioning {
23
- enabled = true
23
+ enabled = var . enable_versioning
24
24
}
25
25
26
26
server_side_encryption_configuration {
@@ -37,6 +37,28 @@ data "aws_iam_policy_document" "bucket_policy" {
37
37
# Deny access to bucket if it's not accessed through HTTPS
38
38
source_json = var. bucket_policy
39
39
40
+ dynamic statement {
41
+ for_each = var. require_tls ? [" enabled" ] : []
42
+ content {
43
+ sid = " EnforceTLS"
44
+ actions = [" s3:GetObject" ]
45
+ resources = [" arn:aws:s3:::${ local . bucket_name } /*" ]
46
+
47
+ principals {
48
+ type = " *"
49
+ identifiers = [" *" ]
50
+ }
51
+
52
+ effect = " Deny"
53
+
54
+ condition {
55
+ test = " Bool"
56
+ variable = " aws:SecureTransport"
57
+ values = [" false" ]
58
+ }
59
+ }
60
+ }
61
+
40
62
statement {
41
63
sid = " AllowPublicRead"
42
64
actions = [" s3:GetObject" ]
Original file line number Diff line number Diff line change @@ -44,3 +44,15 @@ variable "public_read_justification" {
44
44
type = string
45
45
description = " Describe why this bucket must be public and what it is being used for."
46
46
}
47
+
48
+ variable "enable_versioning" {
49
+ type = bool
50
+ description = " Keep old versions of objects in this bucket."
51
+ default = true
52
+ }
53
+
54
+ variable "require_tls" {
55
+ type = bool
56
+ description = " Require TLS to read objects from this bucket."
57
+ default = true
58
+ }
You can’t perform that action at this time.
0 commit comments