@@ -14,6 +14,39 @@ resource "aws_s3_bucket_versioning" "storage_bucket_versioning_config" {
1414 }
1515}
1616
17+ # ensure only secure transport is allowed
18+
19+ resource "aws_s3_bucket_policy" "tfstate_bucket" {
20+ bucket = aws_s3_bucket. storage_bucket . id
21+ policy = data. aws_iam_policy_document . storage_s3_bucket_policy . json
22+ }
23+
24+ data "aws_iam_policy_document" "storage_s3_bucket_policy" {
25+ statement {
26+ sid = " AllowSslRequestsOnly"
27+ actions = [
28+ " s3:*" ,
29+ ]
30+ effect = " Deny"
31+ resources = [
32+ aws_s3_bucket . storage_bucket . arn ,
33+ " ${ aws_s3_bucket . storage_bucket . arn } /*" ,
34+ ]
35+ principals {
36+ type = " *"
37+ identifiers = [" *" ]
38+ }
39+ condition {
40+ test = " Bool"
41+ values = [
42+ " false" ,
43+ ]
44+
45+ variable = " aws:SecureTransport"
46+ }
47+ }
48+ }
49+
1750# Block public access to the bucket
1851resource "aws_s3_bucket_public_access_block" "storage_bucket_block_public_access" {
1952 bucket = aws_s3_bucket. storage_bucket . id
@@ -77,6 +110,36 @@ resource "aws_s3_bucket_logging" "storage_bucket_logging_config" {
77110 target_prefix = " bucket_logs/"
78111}
79112
113+ resource "aws_s3_bucket_policy" "storage_bucket_access_logs" {
114+ bucket = aws_s3_bucket. storage_bucket_access_logs . id
115+ policy = data. aws_iam_policy_document . access_logs_s3_bucket_policy . json
116+ }
117+ data "aws_iam_policy_document" "access_logs_s3_bucket_policy" {
118+ statement {
119+ sid = " AllowSslRequestsOnly"
120+ actions = [
121+ " s3:*" ,
122+ ]
123+ effect = " Deny"
124+ resources = [
125+ aws_s3_bucket . storage_bucket_access_logs . arn ,
126+ " ${ aws_s3_bucket . storage_bucket_access_logs . arn } /*" ,
127+ ]
128+ principals {
129+ type = " *"
130+ identifiers = [" *" ]
131+ }
132+ condition {
133+ test = " Bool"
134+ values = [
135+ " false" ,
136+ ]
137+
138+ variable = " aws:SecureTransport"
139+ }
140+ }
141+ }
142+
80143resource "aws_s3_bucket_server_side_encryption_configuration" "storage_bucket_access_logs_server_side_encryption_config" {
81144 bucket = aws_s3_bucket. storage_bucket_access_logs . id
82145
0 commit comments