Skip to content

Commit

Permalink
Merge pull request #4 from weni-ai/feature/new-acl
Browse files Browse the repository at this point in the history
Add new option to module to add WRITE_ACP to bucket
  • Loading branch information
baltazarweni authored Apr 23, 2024
2 parents b2a919b + aad7598 commit 5431920
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ variable "create_iam_user" {
default = false
}

variable "create_iam_user_write_acl" {
type = bool
default = false
description = "If iam user can use WRITE_ACP on bucket"
}

variable "create_iam_eks_role" {
type = map(any)
default = {}
Expand Down
35 changes: 35 additions & 0 deletions acl.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
resource "aws_s3_bucket_ownership_controls" "bucket_acl" {
count = var.create && var.create_iam_user && var.create_iam_user_write_acl ? 1 : 0
bucket = aws_s3_bucket.bucket[0].id
rule {
object_ownership = "BucketOwnerPreferred"
}
}

resource "aws_s3_bucket_acl" "grant_owner_to_iam" {
count = var.create && var.create_iam_user && var.create_iam_user_write_acl ? 1 : 0
depends_on = [aws_s3_bucket_ownership_controls.bucket_acl[0]]

bucket = aws_s3_bucket.bucket[0].id
access_control_policy {
grant {
grantee {
id = aws_iam_user.bucket_user[0].id
type = "CanonicalUser"
}
permission = "WRITE_ACP"
}

grant {
grantee {
type = "Group"
uri = "http://acs.amazonaws.com/groups/s3/LogDelivery"
}
permission = "READ_ACP"
}

owner {
id = data.aws_canonical_user_id.current.id
}
}
}

0 comments on commit 5431920

Please sign in to comment.