Skip to content

Commit cc05728

Browse files
asiegmanaknysh
andauthored
Adds concept of additional bucket policies (#17)
* Add concept of additional bucket policies * Make linter happy maybe * Update README * Fix conditional Co-Authored-By: Andriy Knysh <[email protected]> * Fix description Co-Authored-By: Andriy Knysh <[email protected]> * Update README * Conditionally create the aggregate policy as well * Line up some white space, terraform fmt * Revert aggregated_policy count conditional as not-supported Co-authored-by: Andriy Knysh <[email protected]>
1 parent b3798be commit cc05728

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Available targets:
8585
| Name | Description | Type | Default | Required |
8686
|------|-------------|:----:|:-----:|:-----:|
8787
| acl | The canned ACL to apply. We recommend `private` to avoid exposing sensitive information | string | `private` | no |
88+
| additional_bucket_policies | Set this to a list of strings containing valid JSON policy statements if you want to add arbitrary additions to the bucket policy | list | `<list>` | no |
8889
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | string | `false` | no |
8990
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list | `<list>` | no |
9091
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
55
| acl | The canned ACL to apply. We recommend `private` to avoid exposing sensitive information | string | `private` | no |
6+
| additional_bucket_policies | Set this to a list of strings containing valid JSON policy statements if you want to add arbitrary additions to the bucket policy | list | `<list>` | no |
67
| allow_encrypted_uploads_only | Set to `true` to prevent uploads of unencrypted objects to S3 bucket | string | `false` | no |
78
| allowed_bucket_actions | List of actions the user is permitted to perform on the S3 bucket | list | `<list>` | no |
89
| attributes | Additional attributes (e.g. `1`) | list | `<list>` | no |

main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@ data "aws_iam_policy_document" "bucket_policy" {
8787
}
8888
}
8989

90+
module "aggregated_policy" {
91+
source = "git::https://github.com/cloudposse/terraform-aws-iam-policy-document-aggregator.git?ref=tags/0.1.2"
92+
source_documents = "${flatten(list(data.aws_iam_policy_document.bucket_policy.*.json, var.additional_bucket_policies))}"
93+
}
94+
9095
resource "aws_s3_bucket_policy" "default" {
91-
count = "${var.enabled == "true" && var.allow_encrypted_uploads_only == "true" ? 1 : 0}"
92-
bucket = "${join("", aws_s3_bucket.default.*.id)}"
96+
count = "${var.enabled == "true" && (var.allow_encrypted_uploads_only == "true" || length(var.additional_bucket_policies) > 0) ? 1 : 0}"
9397

94-
policy = "${join("", data.aws_iam_policy_document.bucket_policy.*.json)}"
98+
bucket = "${join("", aws_s3_bucket.default.*.id)}"
99+
policy = "${module.aggregated_policy.result_document}"
95100
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,9 @@ variable "allow_encrypted_uploads_only" {
9696
default = "false"
9797
description = "Set to `true` to prevent uploads of unencrypted objects to S3 bucket"
9898
}
99+
100+
variable "additional_bucket_policies" {
101+
type = "list"
102+
default = []
103+
description = "Set this to a list of strings containing valid JSON policy statements if you want to add arbitrary additions to the bucket policy"
104+
}

0 commit comments

Comments
 (0)