diff --git a/README.md b/README.md index c2cc627..4456384 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,12 @@ No resources. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [acl](#input\_acl) | Please node ACL is deprecated by AWS in favor of bucket policies.
Defaults to "private" for backwards compatibility,recommended to set `s3_object_ownership` to "BucketOwnerEnforced" instead. | `string` | `"private"` | no | +| [availability\_zone\_id](#input\_availability\_zone\_id) | The ID of the availability zone. | `string` | `""` | no | | [bucket\_logging\_data](#input\_bucket\_logging\_data) | (optional) Bucket logging data |
object({
enable = optional(bool, false)
target_bucket = optional(string, null)
target_prefix = optional(string, null)
})
|
{
"enable": false,
"target_bucket": null,
"target_prefix": null
}
| no | | [bucket\_policy\_doc](#input\_bucket\_policy\_doc) | (optional) S3 bucket Policy doc | `string` | `null` | no | | [cors\_configuration](#input\_cors\_configuration) | List of S3 bucket CORS configurations |
list(object({
id = optional(string)
allowed_headers = optional(list(string))
allowed_methods = optional(list(string))
allowed_origins = optional(list(string))
expose_headers = optional(list(string))
max_age_seconds = optional(number)
}))
| `[]` | no | | [create\_bucket](#input\_create\_bucket) | (optional) Whether to create bucket | `bool` | `true` | no | +| [create\_s3\_directory\_bucket](#input\_create\_s3\_directory\_bucket) | Control the creation of the S3 directory bucket. Set to true to create the bucket, false to skip. | `bool` | `false` | no | | [enable\_versioning](#input\_enable\_versioning) | Whether to enable versioning for the bucket | `bool` | `true` | no | | [event\_notification\_details](#input\_event\_notification\_details) | (optional) S3 event notification details |
object({
enabled = bool
lambda_list = optional(list(object({
lambda_function_arn = string
events = optional(list(string), ["s3:ObjectCreated:*"])
filter_prefix = string
filter_suffix = string
})), [])

queue_list = optional(list(object({
queue_arn = string
events = optional(list(string), ["s3:ObjectCreated:*"])
})), [])

topic_list = optional(list(object({
topic_arn = string
events = optional(list(string), ["s3:ObjectCreated:*"])
})), [])

})
|
{
"enabled": false
}
| no | | [force\_destroy](#input\_force\_destroy) | (Optional, Default:false) Boolean that indicates all objects (including any locked objects) should be deleted from the bucket when the bucket is destroyed so that the bucket can be destroyed without error. These objects are not recoverable. This only deletes objects when the bucket is destroyed, not when setting this parameter to true. Once this parameter is set to true, there must be a successful terraform apply run before a destroy is required to update this value in the resource state. Without a successful terraform apply after this parameter is set, this flag will have no effect. If setting this field in the same operation that would require replacing the bucket or destroying the bucket, this flag will not work. Additionally when importing a bucket, a successful terraform apply is required to set this value in state before it will take effect on a destroy operation. | `bool` | `false` | no | diff --git a/main.tf b/main.tf index fc4ec3c..1992115 100644 --- a/main.tf +++ b/main.tf @@ -18,6 +18,8 @@ module "bucket" { event_notification_details = var.event_notification_details lifecycle_config = var.lifecycle_config transfer_acceleration_enabled = var.transfer_acceleration_enabled + create_s3_directory_bucket = var.create_s3_directory_bucket + availability_zone_id = var.availability_zone_id tags = var.tags } diff --git a/modules/bucket/locals.tf b/modules/bucket/locals.tf new file mode 100644 index 0000000..bcbf3ed --- /dev/null +++ b/modules/bucket/locals.tf @@ -0,0 +1,3 @@ +locals { + directory_bucket_name = var.create_s3_directory_bucket ? "${aws_s3_bucket.this.id}-${var.availability_zone_id}" : "" +} diff --git a/modules/bucket/main.tf b/modules/bucket/main.tf index 2664d4c..ec64c50 100644 --- a/modules/bucket/main.tf +++ b/modules/bucket/main.tf @@ -217,3 +217,15 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" { depends_on = [aws_s3_bucket_versioning.this] } + +/// Directory Bucket +// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_directory_bucket +resource "aws_s3_directory_bucket" "default" { + count = var.create_s3_directory_bucket ? 1 : 0 + bucket = local.directory_bucket_name + force_destroy = var.force_destroy + + location { + name = var.availability_zone_id + } +} diff --git a/modules/bucket/variables.tf b/modules/bucket/variables.tf index a76bdde..3072129 100644 --- a/modules/bucket/variables.tf +++ b/modules/bucket/variables.tf @@ -218,3 +218,14 @@ variable "transfer_acceleration_enabled" { description = "(optional) Whether to enable Trasfer accelaration" default = false } +variable "create_s3_directory_bucket" { + description = "Control the creation of the S3 directory bucket. Set to true to create the bucket, false to skip." + type = bool + default = false +} + +variable "availability_zone_id" { + description = "The ID of the availability zone." + type = string + default = "" +} diff --git a/variables.tf b/variables.tf index c369666..d377653 100644 --- a/variables.tf +++ b/variables.tf @@ -267,3 +267,14 @@ variable "replication_config" { } description = "Replication configuration for S3 bucket" } +variable "create_s3_directory_bucket" { + description = "Control the creation of the S3 directory bucket. Set to true to create the bucket, false to skip." + type = bool + default = false +} + +variable "availability_zone_id" { + description = "The ID of the availability zone." + type = string + default = "" +}