• Stars
    star
    511
  • Rank 86,473 (Top 2 %)
  • Language HCL
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Terraform module to create AWS S3 resources 🇺🇦

AWS S3 bucket Terraform module

Terraform module which creates S3 bucket on AWS with all (or almost all) features provided by Terraform AWS provider.

SWUbanner

These features of S3 bucket configurations are supported:

  • static web-site hosting
  • access logging
  • versioning
  • CORS
  • lifecycle rules
  • server-side encryption
  • object locking
  • Cross-Region Replication (CRR)
  • ELB log delivery bucket policy
  • ALB/NLB log delivery bucket policy

Usage

Private bucket with versioning enabled

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

  bucket = "my-s3-bucket"
  acl    = "private"

  control_object_ownership = true
  object_ownership         = "ObjectWriter"

  versioning = {
    enabled = true
  }
}

Bucket with ELB access log delivery policy attached

module "s3_bucket_for_logs" {
  source = "terraform-aws-modules/s3-bucket/aws"

  bucket = "my-s3-bucket-for-logs"
  acl    = "log-delivery-write"

  # Allow deletion of non-empty bucket
  force_destroy = true

  control_object_ownership = true
  object_ownership         = "ObjectWriter"

  attach_elb_log_delivery_policy = true
}

Bucket with ALB/NLB access log delivery policy attached

module "s3_bucket_for_logs" {
  source = "terraform-aws-modules/s3-bucket/aws"

  bucket = "my-s3-bucket-for-logs"
  acl    = "log-delivery-write"

  # Allow deletion of non-empty bucket
  force_destroy = true

  control_object_ownership = true
  object_ownership         = "ObjectWriter"

  attach_elb_log_delivery_policy = true  # Required for ALB logs
  attach_lb_log_delivery_policy  = true  # Required for ALB/NLB logs
}

Conditional creation

Sometimes you need to have a way to create S3 resources conditionally but Terraform does not allow to use count inside module block, so the solution is to specify argument create_bucket.

# This S3 bucket will not be created
module "s3_bucket" {
  source = "terraform-aws-modules/s3-bucket/aws"

  create_bucket = false
  # ... omitted
}

Terragrunt and variable "..." { type = any }

There is a bug #1211 in Terragrunt related to the way how the variables of type any are passed to Terraform.

This module solves this issue by supporting jsonencode()-string in addition to the expected type (list or map).

In terragrunt.hcl you can write:

inputs = {
  bucket    = "foobar"            # `bucket` has type `string`, no need to jsonencode()
  cors_rule = jsonencode([...])   # `cors_rule` has type `any`, so `jsonencode()` is required
}

Module wrappers

Users of this Terraform module can create multiple similar resources by using for_each meta-argument within module block which became available in Terraform 0.13.

Users of Terragrunt can achieve similar results by using modules provided in the wrappers directory, if they prefer to reduce amount of configuration files.

Examples:

Requirements

Name Version
terraform >= 0.13.1
aws >= 4.9

Providers

Name Version
aws >= 4.9

Modules

No modules.

Resources

Name Type
aws_s3_bucket.this resource
aws_s3_bucket_accelerate_configuration.this resource
aws_s3_bucket_acl.this resource
aws_s3_bucket_analytics_configuration.this resource
aws_s3_bucket_cors_configuration.this resource
aws_s3_bucket_intelligent_tiering_configuration.this resource
aws_s3_bucket_inventory.this resource
aws_s3_bucket_lifecycle_configuration.this resource
aws_s3_bucket_logging.this resource
aws_s3_bucket_metric.this resource
aws_s3_bucket_object_lock_configuration.this resource
aws_s3_bucket_ownership_controls.this resource
aws_s3_bucket_policy.this resource
aws_s3_bucket_public_access_block.this resource
aws_s3_bucket_replication_configuration.this resource
aws_s3_bucket_request_payment_configuration.this resource
aws_s3_bucket_server_side_encryption_configuration.this resource
aws_s3_bucket_versioning.this resource
aws_s3_bucket_website_configuration.this resource
aws_caller_identity.current data source
aws_canonical_user_id.this data source
aws_iam_policy_document.access_log_delivery data source
aws_iam_policy_document.combined data source
aws_iam_policy_document.deny_incorrect_encryption_headers data source
aws_iam_policy_document.deny_incorrect_kms_key_sse data source
aws_iam_policy_document.deny_insecure_transport data source
aws_iam_policy_document.deny_unencrypted_object_uploads data source
aws_iam_policy_document.elb_log_delivery data source
aws_iam_policy_document.inventory_and_analytics_destination_policy data source
aws_iam_policy_document.lb_log_delivery data source
aws_iam_policy_document.require_latest_tls data source
aws_partition.current data source
aws_region.current data source

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
access_log_delivery_policy_source_accounts (Optional) List of AWS Account IDs should be allowed to deliver access logs to this bucket. list(string) [] no
access_log_delivery_policy_source_buckets (Optional) List of S3 bucket ARNs wich should be allowed to deliver access logs to this bucket. list(string) [] no
acl (Optional) The canned ACL to apply. Conflicts with grant string null no
allowed_kms_key_arn The ARN of KMS key which should be allowed in PutObject string null no
analytics_configuration Map containing bucket analytics configuration. any {} no
analytics_self_source_destination Whether or not the analytics source bucket is also the destination bucket. bool false no
analytics_source_account_id The analytics source account id. string null no
analytics_source_bucket_arn The analytics source bucket ARN. string null no
attach_access_log_delivery_policy Controls if S3 bucket should have S3 access log delivery policy attached bool false no
attach_analytics_destination_policy Controls if S3 bucket should have bucket analytics destination policy attached. bool false no
attach_deny_incorrect_encryption_headers Controls if S3 bucket should deny incorrect encryption headers policy attached. bool false no
attach_deny_incorrect_kms_key_sse Controls if S3 bucket policy should deny usage of incorrect KMS key SSE. bool false no
attach_deny_insecure_transport_policy Controls if S3 bucket should have deny non-SSL transport policy attached bool false no
attach_deny_unencrypted_object_uploads Controls if S3 bucket should deny unencrypted object uploads policy attached. bool false no
attach_elb_log_delivery_policy Controls if S3 bucket should have ELB log delivery policy attached bool false no
attach_inventory_destination_policy Controls if S3 bucket should have bucket inventory destination policy attached. bool false no
attach_lb_log_delivery_policy Controls if S3 bucket should have ALB/NLB log delivery policy attached bool false no
attach_policy Controls if S3 bucket should have bucket policy attached (set to true to use value of policy as bucket policy) bool false no
attach_public_policy Controls if a user defined public bucket policy will be attached (set to false to allow upstream to apply defaults to the bucket) bool true no
attach_require_latest_tls_policy Controls if S3 bucket should require the latest version of TLS bool false no
block_public_acls Whether Amazon S3 should block public ACLs for this bucket. bool true no
block_public_policy Whether Amazon S3 should block public bucket policies for this bucket. bool true 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
control_object_ownership Whether to manage S3 Bucket Ownership Controls on this bucket. bool false no
cors_rule List of maps containing rules for Cross-Origin Resource Sharing. any [] no
create_bucket Controls if S3 bucket should be created bool true no
expected_bucket_owner The account ID of the expected bucket owner string 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. bool false no
grant An ACL policy grant. Conflicts with acl any [] no
ignore_public_acls Whether Amazon S3 should ignore public ACLs for this bucket. bool true no
intelligent_tiering Map containing intelligent tiering configuration. any {} no
inventory_configuration Map containing S3 inventory configuration. any {} no
inventory_self_source_destination Whether or not the inventory source bucket is also the destination bucket. bool false no
inventory_source_account_id The inventory source account id. string null no
inventory_source_bucket_arn The inventory source bucket ARN. string null no
lifecycle_rule List of maps containing configuration of object lifecycle management. any [] no
logging Map containing access bucket logging configuration. map(string) {} no
metric_configuration Map containing bucket metric configuration. any [] no
object_lock_configuration Map containing S3 object locking configuration. any {} no
object_lock_enabled Whether S3 bucket should have an Object Lock configuration enabled. bool false no
object_ownership Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. 'BucketOwnerEnforced': ACLs are disabled, and the bucket owner automatically owns and has full control over every object in the bucket. 'BucketOwnerPreferred': Objects uploaded to the bucket change ownership to the bucket owner if the objects are uploaded with the bucket-owner-full-control canned ACL. 'ObjectWriter': The uploading account will own the object if the object is uploaded with the bucket-owner-full-control canned ACL. string "BucketOwnerEnforced" no
owner Bucket owner's display name and ID. Conflicts with acl map(string) {} 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
putin_khuylo Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! bool true no
replication_configuration Map containing cross-region replication configuration. any {} 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
restrict_public_buckets Whether Amazon S3 should restrict public bucket policies for this bucket. bool true no
server_side_encryption_configuration Map containing server-side encryption configuration. any {} no
tags (Optional) A mapping of tags to assign to the bucket. map(string) {} no
versioning Map containing versioning configuration. map(string) {} no
website Map containing static web-site hosting or redirect configuration. any {} no

Outputs

Name Description
s3_bucket_arn The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
s3_bucket_bucket_domain_name The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
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.
s3_bucket_hosted_zone_id The Route 53 Hosted Zone ID for this bucket's region.
s3_bucket_id The name of the bucket.
s3_bucket_lifecycle_configuration_rules The lifecycle rules of the bucket, if the bucket is configured with lifecycle rules. If not, this will be an empty string.
s3_bucket_policy The policy of the bucket, if the bucket is configured with a policy. If not, this will be an empty string.
s3_bucket_region The AWS region this bucket resides in.
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.
s3_bucket_website_endpoint The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

Authors

Module is maintained by Anton Babenko with help from these awesome contributors.

License

Apache 2 Licensed. See LICENSE for full details.

Additional information for users from Russia and Belarus

More Repositories

1

terraform-aws-eks

Terraform module to create Amazon Elastic Kubernetes (EKS) resources 🇺🇦
HCL
4,372
star
2

terraform-aws-vpc

Terraform module to create AWS VPC resources 🇺🇦
HCL
2,949
star
3

terraform-aws-lambda

Terraform module, which takes care of a lot of AWS Lambda/serverless tasks (build dependencies, packages, updates, deployments) in countless combinations 🇺🇦
HCL
899
star
4

terraform-aws-rds

Terraform module to create AWS RDS resources 🇺🇦
HCL
879
star
5

terraform-aws-iam

Terraform module to create AWS IAM resources 🇺🇦
HCL
779
star
6

terraform-aws-ec2-instance

Terraform module to create AWS EC2 instance(s) resources 🇺🇦
HCL
751
star
7

terraform-aws-security-group

Terraform module to create AWS Security Group resources 🇺🇦
HCL
563
star
8

terraform-aws-ecs

Terraform module to create AWS ECS resources 🇺🇦
HCL
555
star
9

terraform-aws-atlantis

Terraform module to deploy Atlantis on AWS Fargate 🇺🇦
HCL
519
star
10

terraform-aws-notify-slack

Terraform module to create AWS resources for sending notifications to Slack 🇺🇦
Python
466
star
11

terraform-aws-alb

Terraform module to create AWS Application/Network Load Balancer (ALB/NLB) resources 🇺🇦
HCL
433
star
12

terraform-aws-rds-aurora

Terraform module to create AWS RDS Aurora resources 🇺🇦
HCL
384
star
13

terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
HCL
292
star
14

terraform-aws-pricing

Terraform module which calculates price of AWS infrastructure (from Terraform state and plan) 🇺🇦
HCL
183
star
15

terraform-aws-acm

Terraform module to create AWS ACM resources 🇺🇦
HCL
182
star
16

terraform-aws-cloudwatch

Terraform module to create AWS Cloudwatch resources 🇺🇦
HCL
163
star
17

terraform-aws-elb

Terraform module to create AWS ELB resources 🇺🇦
HCL
148
star
18

terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) 🇺🇦
HCL
146
star
19

terraform-aws-eventbridge

Terraform module to create AWS EventBridge resources 🇺🇦
HCL
142
star
20

terraform-aws-transit-gateway

Terraform module to create AWS Transit Gateway resources 🇺🇦
HCL
141
star
21

terraform-aws-route53

Terraform module to create AWS Route53 resources 🇺🇦
HCL
126
star
22

terraform-aws-cloudfront

Terraform module to create AWS CloudFront resources 🇺🇦
HCL
119
star
23

terraform-aws-vpn-gateway

Terraform module to create AWS VPN gateway resources 🇺🇦
HCL
111
star
24

terraform-aws-dynamodb-table

Terraform module to create AWS DynamoDB resources 🇺🇦
HCL
100
star
25

terraform-aws-sns

Terraform module to create AWS SNS resources 🇺🇦
HCL
95
star
26

terraform-aws-sqs

Terraform module to create AWS SQS resources 🇺🇦
HCL
92
star
27

terraform-aws-key-pair

Terraform module to create AWS EC2 key pair resources 🇺🇦
HCL
83
star
28

terraform-aws-redshift

Terraform module to create AWS Redshift resources 🇺🇦
HCL
81
star
29

meta

Meta-configurations for repositories, teams, files in terraform-aws-modules organization 🇺🇦
HCL
76
star
30

terraform-aws-solutions

Set of standalone and reusable AWS/DevOps solutions implemented as Terraform modules 🇺🇦
HCL
75
star
31

terraform-aws-step-functions

Terraform module to create AWS Step Functions 🇺🇦
HCL
70
star
32

terraform-aws-dms

Terraform module to create AWS DMS (Database Migration Service) resources 🇺🇦
HCL
62
star
33

terraform-aws-rds-proxy

Terraform module to create AWS RDS Proxy resources 🇺🇦
HCL
56
star
34

terraform-aws-msk-kafka-cluster

Terraform module to create AWS MSK (Managed Streaming for Kafka) resources 🇺🇦
HCL
55
star
35

terraform-aws-datadog-forwarders

Terraform module to create resources on AWS to forward logs/metrics to Datadog 🇺🇦
HCL
53
star
36

terraform-aws-eks-pod-identity

Terraform module to create AWS EKS Pod Identity resources 🇺🇦
HCL
52
star
37

terraform-aws-appsync

Terraform module to create AWS AWS AppSync resources 🇺🇦
HCL
50
star
38

terraform-aws-kms

Terraform module to create AWS KMS resources 🇺🇦
HCL
49
star
39

terraform-aws-ecr

Terraform module to create AWS ECR resources 🇺🇦
HCL
49
star
40

terraform-aws-managed-service-grafana

Terraform module to create AWS Managed Service for Grafana (AMG) resources 🇺🇦
HCL
36
star
41

terraform-aws-batch

Terraform module to create AWS Batch resources 🇺🇦
HCL
35
star
42

terraform-aws-app-runner

Terraform module to create AWS App Runner resources 🇺🇦
HCL
32
star
43

terraform-aws-secrets-manager

Terraform module to create AWS Secrets Manager resources 🇺🇦
HCL
28
star
44

terraform-aws-appconfig

Terraform module to create AWS AppConfig resources 🇺🇦
HCL
27
star
45

terraform-aws-managed-service-prometheus

Terraform module to create AWS Managed Service for Prometheus (AMP) resources 🇺🇦
HCL
26
star
46

terraform-aws-efs

Terraform module to create AWS EFS resources 🇺🇦
HCL
24
star
47

terraform-aws-emr

Terraform module to create AWS EMR resources 🇺🇦
HCL
23
star
48

.github

Meta-GitHub repository for all terraform-aws-modules repositories 🇺🇦
22
star
49

terraform-aws-ssm-parameter

Terraform module to create AWS SSM Parameter resources 🇺🇦
HCL
20
star
50

terraform-aws-s3-object

Terraform module which creates S3 object resources on AWS
HCL
17
star
51

terraform-aws-ebs-optimized

Terraform module to determine if an instance can be flagged for EBS optimization
HCL
17
star
52

terraform-aws-customer-gateway

Terraform module to create AWS Customer Gateway resources 🇺🇦
HCL
17
star
53

terraform-aws-global-accelerator

Terraform module to create AWS Global Accelerator resources 🇺🇦
HCL
16
star
54

terraform-aws-memory-db

Terraform module to create AWS MemoryDB resources 🇺🇦
HCL
16
star
55

terraform-aws-opensearch

Terraform module to create AWS OpenSearch resources 🇺🇦
HCL
15
star
56

terraform-aws-elasticache

Terraform module to create AWS ElastiCache resources 🇺🇦
HCL
12
star
57

terraform-aws-network-firewall

Terraform module to create AWS Network Firewall resources 🇺🇦
HCL
12
star
58

terraform-aws-fsx

Terraform module to create AWS FSx resources 🇺🇦
HCL
4
star
59

atlantis-demo

Demo repository for Atlantis
3
star