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

Added optional s3 directory resource #5

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ No resources.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_acl"></a> [acl](#input\_acl) | Please node ACL is deprecated by AWS in favor of bucket policies.<br>Defaults to "private" for backwards compatibility,recommended to set `s3_object_ownership` to "BucketOwnerEnforced" instead. | `string` | `"private"` | no |
| <a name="input_availability_zone_id"></a> [availability\_zone\_id](#input\_availability\_zone\_id) | The ID of the availability zone. | `string` | `""` | no |
| <a name="input_bucket_logging_data"></a> [bucket\_logging\_data](#input\_bucket\_logging\_data) | (optional) Bucket logging data | <pre>object({<br> enable = optional(bool, false)<br> target_bucket = optional(string, null)<br> target_prefix = optional(string, null)<br> })</pre> | <pre>{<br> "enable": false,<br> "target_bucket": null,<br> "target_prefix": null<br>}</pre> | no |
| <a name="input_bucket_policy_doc"></a> [bucket\_policy\_doc](#input\_bucket\_policy\_doc) | (optional) S3 bucket Policy doc | `string` | `null` | no |
| <a name="input_cors_configuration"></a> [cors\_configuration](#input\_cors\_configuration) | List of S3 bucket CORS configurations | <pre>list(object({<br> id = optional(string)<br> allowed_headers = optional(list(string))<br> allowed_methods = optional(list(string))<br> allowed_origins = optional(list(string))<br> expose_headers = optional(list(string))<br> max_age_seconds = optional(number)<br> }))</pre> | `[]` | no |
| <a name="input_create_bucket"></a> [create\_bucket](#input\_create\_bucket) | (optional) Whether to create bucket | `bool` | `true` | no |
| <a name="input_create_s3_directory_bucket"></a> [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 |
| <a name="input_enable_versioning"></a> [enable\_versioning](#input\_enable\_versioning) | Whether to enable versioning for the bucket | `bool` | `true` | no |
| <a name="input_event_notification_details"></a> [event\_notification\_details](#input\_event\_notification\_details) | (optional) S3 event notification details | <pre>object({<br> enabled = bool<br> lambda_list = optional(list(object({<br> lambda_function_arn = string<br> events = optional(list(string), ["s3:ObjectCreated:*"])<br> filter_prefix = string<br> filter_suffix = string<br> })), [])<br><br> queue_list = optional(list(object({<br> queue_arn = string<br> events = optional(list(string), ["s3:ObjectCreated:*"])<br> })), [])<br><br> topic_list = optional(list(object({<br> topic_arn = string<br> events = optional(list(string), ["s3:ObjectCreated:*"])<br> })), [])<br><br> })</pre> | <pre>{<br> "enabled": false<br>}</pre> | no |
| <a name="input_force_destroy"></a> [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 |
Expand Down
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions modules/bucket/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
directory_bucket_name = var.create_s3_directory_bucket ? "${aws_s3_bucket.this.id}-${var.availability_zone_id}" : ""
}
12 changes: 12 additions & 0 deletions modules/bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 11 additions & 0 deletions modules/bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Loading