forked from terraform-aws-modules/terraform-aws-s3-bucket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite to match other modules, added all existing S3 features
- Loading branch information
1 parent
c5850e4
commit 53ca99f
Showing
17 changed files
with
678 additions
and
524 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
repos: | ||
- repo: git://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.17.0 | ||
rev: v1.19.0 | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terraform_docs | ||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.2.3 | ||
rev: v2.3.0 | ||
hooks: | ||
- id: check-merge-conflict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Complete S3 bucket with most of supported features enabled | ||
|
||
Configuration in this directory creates S3 bucket which demos such capabilities: | ||
- static web-site hosting | ||
- access logging | ||
- versioning | ||
- CORS | ||
- lifecycle rules | ||
- server-side encryption | ||
- object locking | ||
|
||
Please check [S3 replication example](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/master/examples/complete) to see Cross-Region Replication (CRR) supported by this module. | ||
|
||
## 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. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| this\_s3\_bucket\_arn | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. | | ||
| this\_s3\_bucket\_bucket\_domain\_name | The bucket domain name. Will be of format bucketname.s3.amazonaws.com. | | ||
| this\_s3\_bucket\_bucket\_regional\_domain\_name | The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL. | | ||
| this\_s3\_bucket\_hosted\_zone\_id | The Route 53 Hosted Zone ID for this bucket's region. | | ||
| this\_s3\_bucket\_id | The name of the bucket. | | ||
| this\_s3\_bucket\_region | The AWS region this bucket resides in. | | ||
| this\_s3\_bucket\_website\_domain | The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. | | ||
| this\_s3\_bucket\_website\_endpoint | The website endpoint, if the bucket is configured with a website. If not, this will be an empty string. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
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 | ||
} | ||
|
||
module "log_bucket" { | ||
source = "../../" | ||
bucket = "logs-${random_pet.this.id}" | ||
acl = "log-delivery-write" | ||
force_destroy = true | ||
} | ||
|
||
module "s3_bucket" { | ||
source = "../../" | ||
|
||
bucket = "s3-bucket-${random_pet.this.id}" | ||
acl = "private" | ||
force_destroy = true | ||
|
||
tags = { | ||
Owner = "Anton" | ||
} | ||
|
||
versioning = { | ||
enabled = true | ||
} | ||
|
||
website = { | ||
index_document = "index.html" | ||
error_document = "error.html" | ||
routing_rules = jsonencode([{ | ||
Condition : { | ||
KeyPrefixEquals : "docs/" | ||
}, | ||
Redirect : { | ||
ReplaceKeyPrefixWith : "documents/" | ||
} | ||
}]) | ||
|
||
} | ||
|
||
logging = { | ||
target_bucket = module.log_bucket.this_s3_bucket_id | ||
target_prefix = "log/" | ||
} | ||
|
||
cors_rule = { | ||
allowed_methods = ["PUT", "POST"] | ||
allowed_origins = ["https://modules.tf", "https://terraform-aws-modules.modules.tf"] | ||
allowed_headers = ["*"] | ||
expose_headers = ["ETag"] | ||
max_age_seconds = 3000 | ||
} | ||
|
||
lifecycle_rule = [ | ||
{ | ||
id = "log" | ||
enabled = true | ||
prefix = "log/" | ||
|
||
tags = { | ||
rule = "log" | ||
autoclean = "true" | ||
} | ||
|
||
transition = [ | ||
{ | ||
days = 30 | ||
storage_class = "ONEZONE_IA" | ||
}, { | ||
days = 60 | ||
storage_class = "GLACIER" | ||
} | ||
] | ||
|
||
expiration = { | ||
days = 90 | ||
} | ||
|
||
noncurrent_version_expiration = { | ||
days = 30 | ||
} | ||
}, | ||
{ | ||
id = "log1" | ||
enabled = true | ||
prefix = "log1/" | ||
abort_incomplete_multipart_upload_days = 7 | ||
|
||
noncurrent_version_transition = [ | ||
{ | ||
days = 30 | ||
storage_class = "STANDARD_IA" | ||
}, | ||
{ | ||
days = 60 | ||
storage_class = "ONEZONE_IA" | ||
}, | ||
{ | ||
days = 90 | ||
storage_class = "GLACIER" | ||
}, | ||
] | ||
|
||
noncurrent_version_expiration = { | ||
days = 300 | ||
} | ||
}, | ||
] | ||
|
||
server_side_encryption_configuration = { | ||
rule = { | ||
apply_server_side_encryption_by_default = { | ||
kms_master_key_id = aws_kms_key.objects.arn | ||
sse_algorithm = "aws:kms" | ||
} | ||
} | ||
} | ||
|
||
object_lock_configuration = { | ||
object_lock_enabled = "Enabled" | ||
rule = { | ||
default_retention = { | ||
mode = "COMPLIANCE" | ||
years = 5 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.