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

226: Add Expected Bucket Owner #238

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ Available targets:
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_expected_bucket_owner"></a> [expected_bucket_owner](#input\_expected\_bucket\_owner) | Account ID of the expected bucket owner. | `string` | `""` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | When `true`, permits a non-empty S3 bucket to be deleted by first deleting all objects in the bucket.<br>THESE OBJECTS ARE NOT RECOVERABLE even if they were versioned and stored in Glacier. | `bool` | `false` | no |
| <a name="input_grants"></a> [grants](#input\_grants) | A list of policy grants for the bucket, taking a list of permissions.<br>Conflicts with `acl`. Set `acl` to `null` to use this.<br>Deprecated by AWS in favor of bucket policies.<br>Automatically disabled if `s3_object_ownership` is set to "BucketOwnerEnforced". | <pre>list(object({<br> id = string<br> type = string<br> permissions = list(string)<br> uri = string<br> }))</pre> | `[]` | no |
Expand Down
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ resource "aws_s3_bucket_accelerate_configuration" "default" {
resource "aws_s3_bucket_versioning" "default" {
count = local.enabled ? 1 : 0

bucket = local.bucket_id
bucket = local.bucket_id
expected_bucket_owner = var.expected_bucket_owner

versioning_configuration {
status = local.versioning_enabled ? "Enabled" : "Suspended"
Expand All @@ -66,7 +67,8 @@ moved {
resource "aws_s3_bucket_logging" "default" {
for_each = toset(local.enabled && length(var.logging) > 0 ? ["enabled"] : [])

bucket = local.bucket_id
bucket = local.bucket_id
expected_bucket_owner = var.expected_bucket_owner

target_bucket = var.logging[0]["bucket_name"]
target_prefix = var.logging[0]["prefix"]
Expand All @@ -77,7 +79,8 @@ resource "aws_s3_bucket_logging" "default" {
resource "aws_s3_bucket_server_side_encryption_configuration" "default" {
count = local.enabled ? 1 : 0

bucket = local.bucket_id
bucket = local.bucket_id
expected_bucket_owner = var.expected_bucket_owner
Gowiem marked this conversation as resolved.
Show resolved Hide resolved

rule {
bucket_key_enabled = var.bucket_key_enabled
Expand Down Expand Up @@ -166,7 +169,8 @@ resource "aws_s3_bucket_cors_configuration" "default" {
resource "aws_s3_bucket_acl" "default" {
count = local.enabled && var.s3_object_ownership != "BucketOwnerEnforced" ? 1 : 0

bucket = local.bucket_id
bucket = local.bucket_id
expected_bucket_owner = var.expected_bucket_owner

# Conflicts with access_control_policy so this is enabled if no grants
acl = try(length(local.acl_grants), 0) == 0 ? var.acl : null
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,12 @@ variable "bucket_key_enabled" {
EOT
nullable = false
}

variable "expected_bucket_owner" {
type = string
default = ""
houserx-jmcc marked this conversation as resolved.
Show resolved Hide resolved
description = <<-EOT
Account ID of the expected bucket owner.
More information: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html
EOT
}