Skip to content

Commit c07ccf3

Browse files
max-loburcloudpossebotnitrocode
authored
Allow specifying aws_s3_bucket_ownership_controls (#109)
* Sqash implementation * add count * increase timeout * policy is conditional * Auto Format * Update versions.tf Co-authored-by: nitrocode <[email protected]> * Update versions.tf Co-authored-by: nitrocode <[email protected]> * Auto Format Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: nitrocode <[email protected]>
1 parent d9ecab2 commit c07ccf3

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ Available targets:
213213
| Name | Version |
214214
|------|---------|
215215
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
216-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.33 |
216+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
217+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
217218

218219
## Providers
219220

220221
| Name | Version |
221222
|------|---------|
222-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.33 |
223+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
224+
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
223225

224226
## Modules
225227

@@ -236,8 +238,10 @@ Available targets:
236238
| [aws_iam_role.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
237239
| [aws_iam_role_policy_attachment.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
238240
| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
241+
| [aws_s3_bucket_ownership_controls.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
239242
| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
240243
| [aws_s3_bucket_public_access_block.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
244+
| [time_sleep.wait_for_aws_s3_bucket_settings](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
241245
| [aws_iam_policy_document.aggregated_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
242246
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
243247
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -284,6 +288,7 @@ Available targets:
284288
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
285289
| <a name="input_replication_rules"></a> [replication\_rules](#input\_replication\_rules) | DEPRECATED: Use s3\_replication\_rules instead. | `list(any)` | `null` | no |
286290
| <a name="input_restrict_public_buckets"></a> [restrict\_public\_buckets](#input\_restrict\_public\_buckets) | Set to `false` to disable the restricting of making the bucket public | `bool` | `true` | no |
291+
| <a name="input_s3_object_ownership"></a> [s3\_object\_ownership](#input\_s3\_object\_ownership) | Specifies the S3 object ownership control. Valid values are `ObjectWriter` and `BucketOwnerPreferred` | `string` | `"ObjectWriter"` | no |
287292
| <a name="input_s3_replica_bucket_arn"></a> [s3\_replica\_bucket\_arn](#input\_s3\_replica\_bucket\_arn) | A single S3 bucket ARN to use for all replication rules.<br>Note: The destination bucket can be specified in the replication rule itself<br>(which allows for multiple destinations), in which case it will take precedence over this variable. | `string` | `""` | no |
288293
| <a name="input_s3_replication_enabled"></a> [s3\_replication\_enabled](#input\_s3\_replication\_enabled) | Set this to true and specify `s3_replication_rules` to enable replication. `versioning_enabled` must also be `true`. | `bool` | `false` | no |
289294
| <a name="input_s3_replication_rules"></a> [s3\_replication\_rules](#input\_s3\_replication\_rules) | Specifies the replication rules for S3 bucket replication if enabled. You must also set s3\_replication\_enabled to true. | `list(any)` | `null` | no |

docs/terraform.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.33 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
8+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.7 |
89

910
## Providers
1011

1112
| Name | Version |
1213
|------|---------|
13-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.33 |
14+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.0 |
15+
| <a name="provider_time"></a> [time](#provider\_time) | >= 0.7 |
1416

1517
## Modules
1618

@@ -27,8 +29,10 @@
2729
| [aws_iam_role.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
2830
| [aws_iam_role_policy_attachment.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
2931
| [aws_s3_bucket.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
32+
| [aws_s3_bucket_ownership_controls.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
3033
| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
3134
| [aws_s3_bucket_public_access_block.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
35+
| [time_sleep.wait_for_aws_s3_bucket_settings](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
3236
| [aws_iam_policy_document.aggregated_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3337
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
3438
| [aws_iam_policy_document.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
@@ -75,6 +79,7 @@
7579
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
7680
| <a name="input_replication_rules"></a> [replication\_rules](#input\_replication\_rules) | DEPRECATED: Use s3\_replication\_rules instead. | `list(any)` | `null` | no |
7781
| <a name="input_restrict_public_buckets"></a> [restrict\_public\_buckets](#input\_restrict\_public\_buckets) | Set to `false` to disable the restricting of making the bucket public | `bool` | `true` | no |
82+
| <a name="input_s3_object_ownership"></a> [s3\_object\_ownership](#input\_s3\_object\_ownership) | Specifies the S3 object ownership control. Valid values are `ObjectWriter` and `BucketOwnerPreferred` | `string` | `"ObjectWriter"` | no |
7883
| <a name="input_s3_replica_bucket_arn"></a> [s3\_replica\_bucket\_arn](#input\_s3\_replica\_bucket\_arn) | A single S3 bucket ARN to use for all replication rules.<br>Note: The destination bucket can be specified in the replication rule itself<br>(which allows for multiple destinations), in which case it will take precedence over this variable. | `string` | `""` | no |
7984
| <a name="input_s3_replication_enabled"></a> [s3\_replication\_enabled](#input\_s3\_replication\_enabled) | Set this to true and specify `s3_replication_rules` to enable replication. `versioning_enabled` must also be `true`. | `bool` | `false` | no |
8085
| <a name="input_s3_replication_rules"></a> [s3\_replication\_rules](#input\_s3\_replication\_rules) | Specifies the replication rules for S3 bucket replication if enabled. You must also set s3\_replication\_enabled to true. | `list(any)` | `null` | no |

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,22 @@ resource "aws_s3_bucket_public_access_block" "default" {
388388
ignore_public_acls = var.ignore_public_acls
389389
restrict_public_buckets = var.restrict_public_buckets
390390
}
391+
392+
# Per https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
393+
resource "aws_s3_bucket_ownership_controls" "default" {
394+
count = local.enabled ? 1 : 0
395+
bucket = join("", aws_s3_bucket.default.*.id)
396+
397+
rule {
398+
object_ownership = var.s3_object_ownership
399+
}
400+
depends_on = [time_sleep.wait_for_aws_s3_bucket_settings]
401+
}
402+
403+
# Workaround S3 eventual consistency for settings objects
404+
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
405+
count = local.enabled ? 1 : 0
406+
depends_on = [aws_s3_bucket_public_access_block.default, aws_s3_bucket_policy.default]
407+
create_duration = "30s"
408+
destroy_duration = "30s"
409+
}

test/src/examples_complete_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ func TestExamplesCompleteWithReplication(t *testing.T) {
216216

217217
// Verify we're getting back the outputs we expect
218218
assert.NotEmptyf(t, s3ReplicationRoleArn, "If replication is enabled, we should get a Replication Role ARN.")
219-
220219
}
221220

222221
func TestExamplesCompleteWithPrivilegedPrincipals(t *testing.T) {
@@ -373,5 +372,4 @@ func TestExamplesCompleteDisabled(t *testing.T) {
373372

374373
// Verify we're getting back the outputs we expect
375374
assert.Empty(t, s3ReplicationBucketId, "When disabled, module should have no outputs.")
376-
377-
}
375+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,9 @@ variable "transfer_acceleration_enabled" {
280280
default = false
281281
description = "Set this to true to enable S3 Transfer Acceleration for the bucket."
282282
}
283+
284+
variable "s3_object_ownership" {
285+
type = string
286+
default = "ObjectWriter"
287+
description = "Specifies the S3 object ownership control. Valid values are `ObjectWriter` and `BucketOwnerPreferred`"
288+
}

versions.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 2.33"
7+
version = ">= 3.0"
8+
}
9+
time = {
10+
source = "hashicorp/time"
11+
version = ">= 0.7"
812
}
913
}
1014
}

0 commit comments

Comments
 (0)