Skip to content

Commit

Permalink
Refactor and be even more specific
Browse files Browse the repository at this point in the history
If `var.owner["id"]` is provided, then `aws_canonical_user_id` is still not needed.
  • Loading branch information
theipster committed Jul 20, 2023
1 parent abe6d5d commit ef20375
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
data "aws_region" "current" {}

data "aws_canonical_user_id" "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 && try(var.owner["id"], null) == null ? 1 : 0
}

data "aws_caller_identity" "current" {}
Expand All @@ -10,6 +10,8 @@ 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 @@ -41,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

0 comments on commit ef20375

Please sign in to comment.