Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bucket name in policy statements, fixing #81 #82

Merged
merged 11 commits into from
May 3, 2024
23 changes: 20 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
locals {
enabled = module.this.enabled
# We do not use coalesce() here because it is OK if local.bucket_name is empty.
bucket_name = var.bucket_name == null || var.bucket_name == "" ? module.bucket_name.id : var.bucket_name
}

module "bucket_name" {
nitrocode marked this conversation as resolved.
Show resolved Hide resolved
source = "cloudposse/label/null"
version = "0.25.0"

enabled = local.enabled && try(length(var.bucket_name) == 0, false)

id_length_limit = 63 # https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html

context = module.this.context
}

data "aws_elb_service_account" "default" {
count = module.this.enabled ? 1 : 0
}
Expand All @@ -16,7 +33,7 @@ data "aws_iam_policy_document" "default" {
"s3:PutObject"
]
resources = [
"arn:${data.aws_partition.current.partition}:s3:::${module.this.id}/*",
"arn:${data.aws_partition.current.partition}:s3:::${local.bucket_name}/*",
]
}

Expand All @@ -31,7 +48,7 @@ data "aws_iam_policy_document" "default" {
"s3:PutObject"
]
resources = [
"arn:${data.aws_partition.current.partition}:s3:::${module.this.id}/*",
"arn:${data.aws_partition.current.partition}:s3:::${local.bucket_name}/*",
]
condition {
test = "StringEquals"
Expand All @@ -51,7 +68,7 @@ data "aws_iam_policy_document" "default" {
"s3:GetBucketAcl"
]
resources = [
"arn:${data.aws_partition.current.partition}:s3:::${module.this.id}",
"arn:${data.aws_partition.current.partition}:s3:::${local.bucket_name}",
]
}
}
Expand Down
Loading