diff --git a/terraform-modules/aws/s3/folders/README.md b/terraform-modules/aws/s3/folders/README.md new file mode 100644 index 000000000..0ebec5aca --- /dev/null +++ b/terraform-modules/aws/s3/folders/README.md @@ -0,0 +1,30 @@ +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [aws](#provider\_aws) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [aws_s3_object.directory_structure](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [bucket\_name](#input\_bucket\_name) | The name of the S3 bucket | `any` | n/a | yes | +| [folder\_structure](#input\_folder\_structure) | The folder structure to create in S3.
Example usage:
[
"folder1",
"folder2",
"folder3",
"folder4/subfolder1/subfolder2"
] | `list(string)` | n/a | yes | + +## Outputs + +No outputs. diff --git a/terraform-modules/aws/s3/folders/main.tf b/terraform-modules/aws/s3/folders/main.tf new file mode 100644 index 000000000..e5251feda --- /dev/null +++ b/terraform-modules/aws/s3/folders/main.tf @@ -0,0 +1,11 @@ +locals { + folder_structure_map = { for idx, folder in var.folder_structure : idx => folder } +} + +resource "aws_s3_object" "directory_structure" { + for_each = local.folder_structure_map + + bucket = var.bucket_name + key = each.value + content_type = "application/x-directory" +} \ No newline at end of file diff --git a/terraform-modules/aws/s3/folders/variables.tf b/terraform-modules/aws/s3/folders/variables.tf new file mode 100644 index 000000000..c1cd03a91 --- /dev/null +++ b/terraform-modules/aws/s3/folders/variables.tf @@ -0,0 +1,17 @@ +variable "bucket_name" { + description = "The name of the S3 bucket" +} + +variable "folder_structure" { + type = list(string) + description = <<-EOT + The folder structure to create in S3. + Example usage: + [ + "folder1", + "folder2", + "folder3", + "folder4/subfolder1/subfolder2" + ] + EOT +} \ No newline at end of file