-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Support S3 Directory Bucket #310
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
Changes from 8 commits
855b4c6
ef6f159
ce7bc72
76b2d91
249fc87
2cf917e
7307539
f3dfc6a
b97142a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# S3 directory bucket | ||
|
||
Configuration in this directory creates S3 directory bucket and related resources. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.83 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.83 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_complete"></a> [complete](#module\_complete) | ../../ | n/a | | ||
| <a name="module_simple"></a> [simple](#module\_simple) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_kms_key.objects](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| [aws_iam_policy_document.bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_directory_bucket_arn"></a> [directory\_bucket\_arn](#output\_directory\_bucket\_arn) | ARN of the directory bucket. | | ||
| <a name="output_directory_bucket_name"></a> [directory\_bucket\_name](#output\_directory\_bucket\_name) | Name of the directory bucket. | | ||
<!-- END_TF_DOCS --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
locals { | ||
region = "eu-west-1" | ||
} | ||
|
||
provider "aws" { | ||
region = local.region | ||
|
||
# Make it faster by skipping something | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
module "simple" { | ||
source = "../../" | ||
|
||
is_directory_bucket = true | ||
bucket = random_pet.this.id | ||
availability_zone = "${local.region}b" | ||
} | ||
|
||
module "complete" { | ||
source = "../../" | ||
|
||
is_directory_bucket = true | ||
bucket = "${random_pet.this.id}-complete" | ||
availability_zone = "${local.region}b" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned earlier. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, my apologies, I misunderstood initially. I added a data source to find available AZs but I found that even though an AZ is available to me, it might not be an option for directory buckets. In the example, if I set it to index I guess this may not work for everyone so I'm happy to modify this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! 👍 |
||
server_side_encryption_configuration = { | ||
rule = { | ||
bucket_key_enabled = true # required for directory buckets | ||
apply_server_side_encryption_by_default = { | ||
kms_master_key_id = aws_kms_key.objects.arn | ||
sse_algorithm = "aws:kms" | ||
} | ||
} | ||
} | ||
lifecycle_rule = [ | ||
{ | ||
id = "test" | ||
status = "Enabled" | ||
expiration = { | ||
days = 7 | ||
} | ||
}, | ||
{ | ||
id = "logs" | ||
status = "Enabled" | ||
expiration = { | ||
days = 5 | ||
} | ||
filter = { | ||
prefix = "logs/" | ||
object_size_less_than = 10 | ||
} | ||
}, | ||
{ | ||
id = "other" | ||
status = "Enabled" | ||
expiration = { | ||
days = 2 | ||
} | ||
filter = { | ||
prefix = "other/" | ||
} | ||
} | ||
] | ||
attach_policy = true | ||
policy = data.aws_iam_policy_document.bucket_policy.json | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_kms_key" "objects" { | ||
description = "KMS key is used to encrypt bucket objects" | ||
deletion_window_in_days = 7 | ||
} | ||
|
||
data "aws_iam_policy_document" "bucket_policy" { | ||
|
||
statement { | ||
sid = "ReadWriteAccess" | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"s3express:CreateSession", | ||
] | ||
|
||
resources = [module.complete.s3_directory_bucket_arn] | ||
|
||
principals { | ||
identifiers = [data.aws_caller_identity.current.account_id] | ||
type = "AWS" | ||
} | ||
} | ||
|
||
statement { | ||
sid = "ReadOnlyAccess" | ||
effect = "Allow" | ||
|
||
actions = [ | ||
"s3express:CreateSession", | ||
] | ||
|
||
resources = [module.complete.s3_directory_bucket_arn] | ||
|
||
principals { | ||
identifiers = [data.aws_caller_identity.current.account_id] | ||
type = "AWS" | ||
} | ||
|
||
condition { | ||
test = "StringEquals" | ||
values = ["ReadOnly"] | ||
variable = "s3express:SessionMode" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "directory_bucket_name" { | ||
description = "Name of the directory bucket." | ||
value = module.complete.s3_directory_bucket_name | ||
} | ||
|
||
output "directory_bucket_arn" { | ||
description = "ARN of the directory bucket." | ||
value = module.complete.s3_directory_bucket_arn | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.83" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.