Skip to content

Commit b601290

Browse files
Conditionally create aws_s3_bucket_public_access_block (#94)
* Conditionally create aws_s3_bucket_public_access_block It's not needed if none of its options are enabled. * Pull out an expression into a local Co-authored-by: nitrocode <[email protected]>
1 parent 95da7ac commit b601290

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ locals {
77
# Deprecate `replication_rules` in favor of `s3_replication_rules` to keep all the replication related
88
# inputs grouped under s3_replica[tion]
99
s3_replication_rules = var.replication_rules == null ? var.s3_replication_rules : var.replication_rules
10+
11+
public_access_block_enabled = var.block_public_acls || var.block_public_policy || var.ignore_public_acls || var.restrict_public_buckets
1012
}
1113

1214
resource "aws_s3_bucket" "default" {
@@ -374,7 +376,7 @@ resource "aws_s3_bucket_policy" "default" {
374376
# https://www.terraform.io/docs/providers/aws/r/s3_bucket_public_access_block.html
375377
# for the nuances of the blocking options
376378
resource "aws_s3_bucket_public_access_block" "default" {
377-
count = local.enabled ? 1 : 0
379+
count = module.this.enabled && local.public_access_block_enabled ? 1 : 0
378380
bucket = join("", aws_s3_bucket.default.*.id)
379381

380382
block_public_acls = var.block_public_acls

0 commit comments

Comments
 (0)