Skip to content

truerocha/terraform-aws-s3-bucket

 
 

Repository files navigation

AWS S3 bucket Terraform module

Terraform module which creates S3 bucket resources on AWS.

This type of resources are supported:

These S3 Bucket configurations are supported:

  • cors
  • lifecycle-rules
  • logging
  • replication (Cross Region Replication - CRR)*
  • versioning
  • website
These configurations are not supported yet:

In Cross Region Replication (in replication_configuration/rules block):
- priority (the argument is not supported yet).
- filter (the argument is not supported yet).

Object Lock Configuration block(object_lock_configuration) (this configuration block is not supported yet).

Terraform versions

Only Terraform 0.12 is supported.

Usage

  • Private Bucket
module "s3_bucket" {
  source = "terraform-aws-modules/s3-bucket/aws"

  bucket = "s3-tf-example-versioning"
  acl    = "private"

  versioning_inputs = [
    {
      enabled = true
      mfa_delete = null
    },
  ]
}

Examples:

Inputs notes

The Terraform "aws_s3_bucket" resource has some nested configuration blocks and this was translated
to this module as lists of objects. Each configuration block was renamed as it follows: 
<CONFIG_BLOCK_NAME>_inputs
module "aws_s3_bucket" {
  source = "../.."
  bucket = "s3-tf-example-logging"
  acl    = "private"

  logging_inputs = [
  {
    target_bucket = "s3-tf-example-logger"
    target_prefix = "log/"
  },
  ]

The logging_inputs list will be converted to a logging configuration block:

logging {
  target_bucket = "s3-tf-example-logger"
  target_prefix = "log/"
}

Inputs

Name Description Type Default Required
acceleration_status (Optional) Sets the accelerate configuration of an existing bucket. Can be Enabled or Suspended. string "null" no
acl (Optional) The canned ACL to apply. Defaults to 'private'. string "private" no
bucket (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. string "null" no
bucket_prefix (Optional, Forces new resource) Creates a unique bucket name beginning with the specified prefix. Conflicts with bucket. string "null" no
cors_rule_inputs object "null" no
force_destroy (Optional, Default:false ) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. string "false" no
lifecycle_rule_inputs object "null" no
logging_inputs object "null" no
object_lock_configuration_inputs object "null" no
policy (Optional) A valid bucket policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. For more information about building AWS IAM policy documents with Terraform, see the AWS IAM Policy Document Guide. string "null" no
region (Optional) If specified, the AWS region this bucket should reside in. Otherwise, the region used by the callee. string "null" no
replication_configuration_inputs object "null" no
request_payer (Optional) Specifies who should bear the cost of Amazon S3 data transfer. Can be either BucketOwner or Requester. By default, the owner of the S3 bucket would incur the costs of any data transfer. See Requester Pays Buckets developer guide for more information. string "null" no
server_side_encryption_configuration_inputs object "null" no
tags (Optional) A mapping of tags to assign to the bucket. map {} no
versioning_inputs object "null" no
website_inputs object "null" no

Outputs

Name Description
arn The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
bucket_domain_name The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
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.
hosted_zone_id The Route 53 Hosted Zone ID for this bucket's region.
id The name of the bucket.
region The AWS region this bucket resides in.
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.
website_endpoint The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

Authors

Module managed by Anton Babenko.

License

Apache 2 Licensed. See LICENSE for full details.

About

Terraform module which creates S3 bucket resources on AWS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 99.0%
  • Makefile 1.0%