Skip to content

Commit 400a517

Browse files
committed
fix: Fixed placeholders for disabled buckets
1 parent 06b96ee commit 400a517

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Note that this example may create resources which cost money. Run `terraform des
4545
| Name | Source | Version |
4646
|------|--------|---------|
4747
| <a name="module_cloudfront_log_bucket"></a> [cloudfront\_log\_bucket](#module\_cloudfront\_log\_bucket) | ../../ | n/a |
48+
| <a name="module_disabled"></a> [disabled](#module\_disabled) | ../../ | n/a |
4849
| <a name="module_log_bucket"></a> [log\_bucket](#module\_log\_bucket) | ../../ | n/a |
4950
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | ../../ | n/a |
5051
| <a name="module_simple_bucket"></a> [simple\_bucket](#module\_simple\_bucket) | ../../ | n/a |

examples/complete/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,9 @@ module "s3_bucket" {
410410
# sse_algorithm = "AES256"
411411
# }
412412
}
413+
414+
module "disabled" {
415+
source = "../../"
416+
417+
create_bucket = false
418+
}

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ locals {
1818

1919
# Placeholders in the policy document to be replaced with the actual values
2020
policy_placeholders = {
21-
"_S3_BUCKET_ID_" = var.is_directory_bucket ? aws_s3_directory_bucket.this[0].bucket : aws_s3_bucket.this[0].id,
22-
"_S3_BUCKET_ARN_" = var.is_directory_bucket ? aws_s3_directory_bucket.this[0].arn : aws_s3_bucket.this[0].arn,
23-
"_AWS_ACCOUNT_ID_" = data.aws_caller_identity.current.account_id
21+
"_S3_BUCKET_ID_" = try(var.is_directory_bucket ? aws_s3_directory_bucket.this[0].bucket : aws_s3_bucket.this[0].id, null),
22+
"_S3_BUCKET_ARN_" = try(var.is_directory_bucket ? aws_s3_directory_bucket.this[0].arn : aws_s3_bucket.this[0].arn, null),
23+
"_AWS_ACCOUNT_ID_" = try(data.aws_caller_identity.current.account_id, null)
2424
}
2525

2626
policy = local.create_bucket && local.attach_policy ? replace(

0 commit comments

Comments
 (0)