Skip to content

Commit

Permalink
feat: Stop requiring s3:ListAllMyBuckets IAM permission unless need…
Browse files Browse the repository at this point in the history
…ed (for bucket ACL) (#243)
  • Loading branch information
theipster authored Aug 22, 2023
1 parent d371175 commit 74fcc60
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
data "aws_region" "current" {}

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

data "aws_caller_identity" "current" {}

data "aws_partition" "current" {}
locals {
create_bucket = var.create_bucket && var.putin_khuylo

create_bucket_acl = (var.acl != null && var.acl != "null") || length(local.grants) > 0

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

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

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

bucket = aws_s3_bucket.this[0].id
expected_bucket_owner = var.expected_bucket_owner
Expand Down Expand Up @@ -67,7 +71,7 @@ resource "aws_s3_bucket_acl" "this" {
}

owner {
id = try(var.owner["id"], data.aws_canonical_user_id.this.id)
id = try(var.owner["id"], data.aws_canonical_user_id.this[0].id)
display_name = try(var.owner["display_name"], null)
}
}
Expand Down

0 comments on commit 74fcc60

Please sign in to comment.