Skip to content

Commit

Permalink
s3 folders structure (#442)
Browse files Browse the repository at this point in the history
A simple module to create folders in an s3 bucket
  • Loading branch information
bcarranza authored Sep 11, 2023
1 parent 0dbd79d commit da99b8c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions terraform-modules/aws/s3/folders/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [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 |
|------|-------------|------|---------|:--------:|
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | The name of the S3 bucket | `any` | n/a | yes |
| <a name="input_folder_structure"></a> [folder\_structure](#input\_folder\_structure) | The folder structure to create in S3. <br>Example usage:<br>[<br> "folder1",<br> "folder2",<br> "folder3",<br> "folder4/subfolder1/subfolder2"<br>] | `list(string)` | n/a | yes |

## Outputs

No outputs.
11 changes: 11 additions & 0 deletions terraform-modules/aws/s3/folders/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
17 changes: 17 additions & 0 deletions terraform-modules/aws/s3/folders/variables.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit da99b8c

Please sign in to comment.