Skip to content

Commit 42320bf

Browse files
houserx-ioannishouserx-jmccGowiem
authored
feat: add expected_bucket_owner variable (#238)
* 226: Add Expected Bucket Owner * Update variables.tf Co-authored-by: Matt Gowie <matt@masterpoint.io> * fix: commit make results --------- Co-authored-by: John McCall <129085294+houserx-jmcc@users.noreply.github.com> Co-authored-by: Matt Gowie <matt@masterpoint.io> Co-authored-by: John McCall <john.mccall@houserx.com>
1 parent 19b011a commit 42320bf

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Available targets:
280280
| <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 |
281281
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
282282
| <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 |
283+
| <a name="input_expected_bucket_owner"></a> [expected\_bucket\_owner](#input\_expected\_bucket\_owner) | Account ID of the expected bucket owner. <br>More information: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html | `string` | `null` | no |
283284
| <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 |
284285
| <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 |
285286
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
| <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 |
7373
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
7474
| <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 |
75+
| <a name="input_expected_bucket_owner"></a> [expected\_bucket\_owner](#input\_expected\_bucket\_owner) | Account ID of the expected bucket owner. <br>More information: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html | `string` | `null` | no |
7576
| <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 |
7677
| <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 |
7778
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ resource "aws_s3_bucket_accelerate_configuration" "default" {
5151
resource "aws_s3_bucket_versioning" "default" {
5252
count = local.enabled ? 1 : 0
5353

54-
bucket = local.bucket_id
54+
bucket = local.bucket_id
55+
expected_bucket_owner = var.expected_bucket_owner
5556

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

69-
bucket = local.bucket_id
70+
bucket = local.bucket_id
71+
expected_bucket_owner = var.expected_bucket_owner
7072

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

80-
bucket = local.bucket_id
82+
bucket = local.bucket_id
83+
expected_bucket_owner = var.expected_bucket_owner
8184

8285
rule {
8386
bucket_key_enabled = var.bucket_key_enabled
@@ -166,7 +169,8 @@ resource "aws_s3_bucket_cors_configuration" "default" {
166169
resource "aws_s3_bucket_acl" "default" {
167170
count = local.enabled && var.s3_object_ownership != "BucketOwnerEnforced" ? 1 : 0
168171

169-
bucket = local.bucket_id
172+
bucket = local.bucket_id
173+
expected_bucket_owner = var.expected_bucket_owner
170174

171175
# Conflicts with access_control_policy so this is enabled if no grants
172176
acl = try(length(local.acl_grants), 0) == 0 ? var.acl : null

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,12 @@ variable "bucket_key_enabled" {
457457
EOT
458458
nullable = false
459459
}
460+
461+
variable "expected_bucket_owner" {
462+
type = string
463+
default = null
464+
description = <<-EOT
465+
Account ID of the expected bucket owner.
466+
More information: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-owner-condition.html
467+
EOT
468+
}

0 commit comments

Comments
 (0)