Skip to content

Commit 74fcc60

Browse files
authored
feat: Stop requiring s3:ListAllMyBuckets IAM permission unless needed (for bucket ACL) (#243)
1 parent d371175 commit 74fcc60

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
data "aws_region" "current" {}
22

3-
data "aws_canonical_user_id" "this" {}
3+
data "aws_canonical_user_id" "this" {
4+
count = local.create_bucket && local.create_bucket_acl && try(var.owner["id"], null) == null ? 1 : 0
5+
}
46

57
data "aws_caller_identity" "current" {}
68

79
data "aws_partition" "current" {}
810
locals {
911
create_bucket = var.create_bucket && var.putin_khuylo
1012

13+
create_bucket_acl = (var.acl != null && var.acl != "null") || length(local.grants) > 0
14+
1115
attach_policy = var.attach_require_latest_tls_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_inventory_destination_policy || var.attach_deny_incorrect_encryption_headers || var.attach_deny_incorrect_kms_key_sse || var.attach_deny_unencrypted_object_uploads || var.attach_policy
1216

1317
# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
@@ -39,7 +43,7 @@ resource "aws_s3_bucket_logging" "this" {
3943
}
4044

4145
resource "aws_s3_bucket_acl" "this" {
42-
count = local.create_bucket && ((var.acl != null && var.acl != "null") || length(local.grants) > 0) ? 1 : 0
46+
count = local.create_bucket && local.create_bucket_acl ? 1 : 0
4347

4448
bucket = aws_s3_bucket.this[0].id
4549
expected_bucket_owner = var.expected_bucket_owner
@@ -67,7 +71,7 @@ resource "aws_s3_bucket_acl" "this" {
6771
}
6872

6973
owner {
70-
id = try(var.owner["id"], data.aws_canonical_user_id.this.id)
74+
id = try(var.owner["id"], data.aws_canonical_user_id.this[0].id)
7175
display_name = try(var.owner["display_name"], null)
7276
}
7377
}

0 commit comments

Comments
 (0)