Categorygithub.com/trussworks/terraform-aws-s3-private-bucket
repository
3.7.1+incompatible
Repository: https://github.com/trussworks/terraform-aws-s3-private-bucket.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Creates a private S3 bucket with good defaults:

  • Private only objects
  • Encryption
  • Versioning
  • Access logging
  • Storage analytics

The following policy rules are set:

  • Deny uploading public objects.
  • Deny updating policy to allow public objects.

The following ACL rules are set:

  • Retroactively remove public access granted through public ACLs
  • Deny updating ACL to public

The following lifecycle rules are set:

  • Incomplete multipart uploads are deleted after 14 days.
  • Expired object delete markers are deleted.
  • Noncurrent object versions transition to the Standard - Infrequent Access storage class after 30 days.
  • Noncurrent object versions expire after 365 days.

Terraform Versions

Terraform 0.13 and newer. Pin module version to ~> 3.X. Submit pull-requests to master branch.

Terraform 0.12. Pin module version to ~> 2.X. Submit pull-requests to terraform012 branch.

Usage

module "aws-s3-bucket" {
  source         = "trussworks/s3-private-bucket/aws"
  bucket         = "my-bucket-name"
  logging_bucket = "my-aws-logs"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

Requirements

NameVersion
terraform>= 0.13.0
aws>= 3.0, < 4.0

Providers

NameVersion
aws>= 3.0, < 4.0

Modules

No modules.

Resources

NameType
aws_s3_bucket.private_bucketresource
aws_s3_bucket_analytics_configuration.private_analytics_configresource
aws_s3_bucket_inventory.inventoryresource
aws_s3_bucket_public_access_block.public_access_blockresource
aws_caller_identity.currentdata source
aws_iam_account_alias.currentdata source
aws_iam_policy_document.supplemental_policydata source
aws_partition.currentdata source

Inputs

NameDescriptionTypeDefaultRequired
abort_incomplete_multipart_upload_daysNumber of days until aborting incomplete multipart uploadsnumber14no
bucketThe name of the bucket.stringn/ayes
bucket_key_enabledWhether or not to use Amazon S3 Bucket Keys for SSE-KMS.boolfalseno
cors_rulesList of maps containing rules for Cross-Origin Resource Sharing.list(any)[]no
custom_bucket_policyJSON formatted bucket policy to attach to the bucket.string""no
enable_analyticsEnables storage class analytics on the bucket.booltrueno
enable_bucket_force_destroyIf set to true, Bucket will be emptied and destroyed when terraform destroy is run.boolfalseno
enable_bucket_inventoryIf set to true, Bucket Inventory will be enabled.boolfalseno
enable_s3_public_access_blockBool for toggling whether the s3 public access block resource should be enabled.booltrueno
enable_versioningEnables versioning on the bucket.booltrueno
expirationexpiration blockslist(any)
[
{
"expired_object_delete_marker": true
}
]
no
inventory_bucket_formatThe format for the inventory file. Default is ORC. Options are ORC or CSV.string"ORC"no
kms_master_key_idThe AWS KMS master key ID used for the SSE-KMS encryption.string""no
logging_bucketThe S3 bucket to send S3 access logs.string""no
noncurrent_version_expirationNumber of days until non-current version of object expiresnumber365no
noncurrent_version_transitionsNon-current version transition blockslist(any)
[
{
"days": 30,
"storage_class": "STANDARD_IA"
}
]
no
schedule_frequencyThe S3 bucket inventory frequency. Defaults to Weekly. Options are 'Weekly' or 'Daily'.string"Weekly"no
sse_algorithmThe server-side encryption algorithm to use. Valid values are AES256 and aws:kmsstring"AES256"no
tagsA mapping of tags to assign to the bucket.map(string){}no
transitionsCurrent version transition blockslist(any)[]no
use_account_alias_prefixWhether to prefix the bucket name with the AWS account alias.stringtrueno

Outputs

NameDescription
arnThe ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
bucket_domain_nameThe bucket domain name.
bucket_regional_domain_nameThe bucket region-specific domain name.
idThe name of the bucket.
nameThe Name of the bucket. Will be of format bucketprefix-bucketname.

Developer Setup

Install dependencies (macOS)

brew install pre-commit go terraform terraform-docs

Testing

Terratest is being used for automated testing with this module. Tests in the test folder can be run locally by running the following command:

make test

Or with aws-vault:

AWS_VAULT_KEYCHAIN_NAME=<NAME> aws-vault exec <PROFILE> -- make test

CHANGELOG

This terraform module is undergoing an experiment where we keep a CHANGELOG for it. We're still trying to figure out how to automate this process and, for now, are manually running the command.

The changelog should be updated every time a new GitHub release is cut.

To do so, you should have a Github token with "repo" scope that can be loaded in as an environment variable. You can find more info here.

export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"

The command to run on your terminal:

docker run --env CHANGELOG_GITHUB_TOKEN="$CHANGELOG_GITHUB_TOKEN" --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -u trussworks -p terraform-aws-s3-private-bucket