Skip to content

Commit b8bacdb

Browse files
authored
[feature] aws-s3-private-bucket add canned acl variable (#307)
Adds support for passing in a canned acl variable. Defaults to "private" for backwards compatibility. Canned acl variable is ignored if grants argument is passed.
1 parent be13877 commit b8bacdb

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

aws-s3-account-public-access-block/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ locals {
55

66

77
# These only affect new acls and policies by rejecting requests that contain them
8-
block_public_acls = !local.is_none # all or new
9-
block_public_policy = !local.is_none # all or new
8+
block_public_acls = ! local.is_none # all or new
9+
block_public_policy = ! local.is_none # all or new
1010

1111
# These affect existing buckets, policies, and acls
1212
ignore_public_acls = local.is_all

aws-s3-private-bucket/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
locals {
22
# If grants are defined, we use `grant` to grant permissions, otherwise it will use the `acl` to grant permissions
3-
acl = length(var.grants) == 0 ? "private" : null
3+
acl = length(var.grants) == 0 ? var.acl : null
44

5-
# `canonical_user_id` and `uri` shuold be specified exclusively in each grant, so we skip the invalid inputs in grants
5+
# `canonical_user_id` and `uri` should be specified exclusively in each grant, so we skip the invalid inputs in grants
66
# invalid input is the case that they are both or neither specified
77
valid_grants = [for grant in var.grants : {
88
canonical_user_id = lookup(grant, "canonical_user_id", null)
99
uri = lookup(grant, "uri", null)
1010
permissions = grant.permissions
11-
} if !(
11+
} if ! (
1212
(lookup(grant, "canonical_user_id", null) != null && lookup(grant, "uri", null) != null) ||
1313
(lookup(grant, "canonical_user_id", null) == null && lookup(grant, "uri", null) == null)
1414
)

aws-s3-private-bucket/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ variable "grants" {
8787
default = []
8888
description = "A list of objects containing the grant configurations. Used when we want to grant permissions to AWS accounts via the S3 ACL system."
8989
}
90+
91+
variable "acl" {
92+
type = string
93+
default = "private"
94+
description = "Canned ACL to use if grants object is not given. See https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl"
95+
}

0 commit comments

Comments
 (0)