-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add inventory config support (#192)
Co-authored-by: magreenbaum <magreenbaum>
- Loading branch information
1 parent
4ee2d93
commit 8836d0f
Showing
10 changed files
with
409 additions
and
2 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
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 |
---|---|---|
|
@@ -347,5 +347,4 @@ module "s3_bucket" { | |
name = "all" | ||
} | ||
] | ||
|
||
} |
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,55 @@ | ||
# S3 bucket with Inventory Configurations | ||
|
||
Configuration in this directory creates an S3 bucket with several inventory configurations including a different source and destination for inventory reports generated. | ||
|
||
Please check [complete example](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/tree/master/examples/complete) to see all other features supported by this module. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.9 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.9 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_inventory_destination_bucket"></a> [inventory\_destination\_bucket](#module\_inventory\_destination\_bucket) | ../../ | n/a | | ||
| <a name="module_inventory_source_bucket"></a> [inventory\_source\_bucket](#module\_inventory\_source\_bucket) | ../../ | n/a | | ||
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a | | ||
| <a name="module_multi_inventory_configurations_bucket"></a> [multi\_inventory\_configurations\_bucket](#module\_multi\_inventory\_configurations\_bucket) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [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 | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_s3_bucket_arn"></a> [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. | | ||
| <a name="output_s3_bucket_bucket_domain_name"></a> [s3\_bucket\_bucket\_domain\_name](#output\_s3\_bucket\_bucket\_domain\_name) | The bucket domain name. Will be of format bucketname.s3.amazonaws.com. | | ||
| <a name="output_s3_bucket_bucket_regional_domain_name"></a> [s3\_bucket\_bucket\_regional\_domain\_name](#output\_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. | | ||
| <a name="output_s3_bucket_hosted_zone_id"></a> [s3\_bucket\_hosted\_zone\_id](#output\_s3\_bucket\_hosted\_zone\_id) | The Route 53 Hosted Zone ID for this bucket's region. | | ||
| <a name="output_s3_bucket_id"></a> [s3\_bucket\_id](#output\_s3\_bucket\_id) | The name of the bucket. | | ||
| <a name="output_s3_bucket_region"></a> [s3\_bucket\_region](#output\_s3\_bucket\_region) | The AWS region this bucket resides in. | | ||
| <a name="output_s3_bucket_website_domain"></a> [s3\_bucket\_website\_domain](#output\_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. | | ||
| <a name="output_s3_bucket_website_endpoint"></a> [s3\_bucket\_website\_endpoint](#output\_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,155 @@ | ||
locals { | ||
bucket_name = "s3-bucket-${random_pet.this.id}" | ||
region = "eu-west-1" | ||
} | ||
|
||
provider "aws" { | ||
region = local.region | ||
|
||
# Make it faster by skipping something | ||
skip_get_ec2_platforms = true | ||
skip_metadata_api_check = true | ||
skip_region_validation = true | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
} | ||
|
||
data "aws_caller_identity" "current" {} | ||
|
||
module "multi_inventory_configurations_bucket" { | ||
source = "../../" | ||
|
||
bucket = local.bucket_name | ||
|
||
force_destroy = true | ||
|
||
attach_policy = true | ||
attach_inventory_destination_policy = true | ||
inventory_self_source_destination = true | ||
acl = "private" # "acl" conflicts with "grant" and "owner" | ||
|
||
versioning = { | ||
status = true | ||
mfa_delete = false | ||
} | ||
|
||
inventory_configuration = { | ||
|
||
# Same source and destination buckets | ||
daily = { | ||
included_object_versions = "Current" | ||
destination = { | ||
format = "CSV" | ||
encryption = { | ||
encryption_type = "sse_kms" | ||
kms_key_id = module.kms.key_arn | ||
} | ||
} | ||
filter = { | ||
prefix = "documents/" | ||
} | ||
frequency = "Daily" | ||
} | ||
|
||
weekly = { | ||
included_object_versions = "All" | ||
destination = { | ||
format = "CSV" | ||
} | ||
frequency = "Weekly" | ||
} | ||
|
||
# Different destination bucket | ||
destination_other = { | ||
included_object_versions = "All" | ||
destination = { | ||
bucket_arn = module.inventory_destination_bucket.s3_bucket_arn | ||
format = "Parquet" | ||
encryption = { | ||
encryption_type = "sse_s3" | ||
} | ||
} | ||
frequency = "Weekly" | ||
optional_fields = ["Size", "EncryptionStatus", "StorageClass", "ChecksumAlgorithm"] | ||
} | ||
|
||
# Different source bucket | ||
source_other = { | ||
included_object_versions = "Current" | ||
bucket = module.inventory_source_bucket.s3_bucket_id | ||
destination = { | ||
format = "ORC" | ||
encryption = { | ||
encryption_type = "sse_s3" | ||
} | ||
} | ||
frequency = "Daily" | ||
} | ||
} | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/configure-inventory.html#configure-inventory-kms-key-policy | ||
module "kms" { | ||
source = "terraform-aws-modules/kms/aws" | ||
|
||
description = "Key example for Inventory S3 destination encyrption" | ||
deletion_window_in_days = 7 | ||
key_statements = [ | ||
{ | ||
sid = "s3InventoryPolicy" | ||
actions = [ | ||
"kms:GenerateDataKey", | ||
] | ||
resources = ["*"] | ||
|
||
principals = [ | ||
{ | ||
type = "Service" | ||
identifiers = ["s3.amazonaws.com"] | ||
} | ||
] | ||
|
||
conditions = [ | ||
{ | ||
test = "StringEquals" | ||
variable = "aws:SourceAccount" | ||
values = [ | ||
data.aws_caller_identity.current.id, | ||
] | ||
}, | ||
{ | ||
test = "ArnLike" | ||
variable = "aws:SourceARN" | ||
values = [ | ||
module.inventory_source_bucket.s3_bucket_arn, | ||
module.multi_inventory_configurations_bucket.s3_bucket_arn | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
module "inventory_destination_bucket" { | ||
source = "../../" | ||
|
||
bucket = "inventory-destination-${random_pet.this.id}" | ||
acl = "private" # "acl" conflicts with "grant" and "owner" | ||
force_destroy = true | ||
attach_policy = true | ||
attach_inventory_destination_policy = true | ||
inventory_source_bucket_arn = module.multi_inventory_configurations_bucket.s3_bucket_arn | ||
inventory_source_account_id = data.aws_caller_identity.current.id | ||
} | ||
|
||
module "inventory_source_bucket" { | ||
source = "../../" | ||
|
||
bucket = "inventory-source-${random_pet.this.id}" | ||
acl = "private" # "acl" conflicts with "grant" and "owner" | ||
force_destroy = true | ||
} |
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,39 @@ | ||
output "s3_bucket_id" { | ||
description = "The name of the bucket." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_id | ||
} | ||
|
||
output "s3_bucket_arn" { | ||
description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_arn | ||
} | ||
|
||
output "s3_bucket_bucket_domain_name" { | ||
description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_bucket_domain_name | ||
} | ||
|
||
output "s3_bucket_bucket_regional_domain_name" { | ||
description = "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." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_bucket_regional_domain_name | ||
} | ||
|
||
output "s3_bucket_hosted_zone_id" { | ||
description = "The Route 53 Hosted Zone ID for this bucket's region." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_hosted_zone_id | ||
} | ||
|
||
output "s3_bucket_region" { | ||
description = "The AWS region this bucket resides in." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_region | ||
} | ||
|
||
output "s3_bucket_website_endpoint" { | ||
description = "The website endpoint, if the bucket is configured with a website. If not, this will be an empty string." | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_website_endpoint | ||
} | ||
|
||
output "s3_bucket_website_domain" { | ||
description = "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. " | ||
value = module.multi_inventory_configurations_bucket.s3_bucket_website_domain | ||
} |
Empty file.
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,14 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 4.9" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
Oops, something went wrong.