Skip to content

Commit 70000e3

Browse files
committed
Make requiring TLS optional
1 parent b3d02f1 commit 70000e3

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

aws-s3-public-bucket/main.tf

+16-13
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,25 @@ data "aws_iam_policy_document" "bucket_policy" {
3737
# Deny access to bucket if it's not accessed through HTTPS
3838
source_json = var.bucket_policy
3939

40-
statement {
41-
sid = "EnforceTLS"
42-
actions = ["s3:GetObject"]
43-
resources = ["arn:aws:s3:::${local.bucket_name}/*"]
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}/*"]
4446

45-
principals {
46-
type = "*"
47-
identifiers = ["*"]
48-
}
47+
principals {
48+
type = "*"
49+
identifiers = ["*"]
50+
}
4951

50-
effect = "Deny"
52+
effect = "Deny"
5153

52-
condition {
53-
test = "Bool"
54-
variable = "aws:SecureTransport"
55-
values = ["false"]
54+
condition {
55+
test = "Bool"
56+
variable = "aws:SecureTransport"
57+
values = ["false"]
58+
}
5659
}
5760
}
5861

aws-s3-public-bucket/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ variable "enable_versioning" {
5050
description = "Keep old versions of objects in this bucket."
5151
default = true
5252
}
53+
54+
variable "require_tls" {
55+
type = bool
56+
description = "Require TLS to read objects from this bucket."
57+
default = true
58+
}

0 commit comments

Comments
 (0)