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

s3 folders structure #442

Merged
merged 5 commits into from
Sep 11, 2023
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
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
}