Skip to content

Terraform module to create 2 S3 buckets in a replicated fashion, compliant with logging, versioning and encryption at rest.

License

Notifications You must be signed in to change notification settings

Lupus-Metallum/terraform-aws-replicated-s3-bucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

terraform-aws-replicated-s3-bucket

Example usage

module "s3_replicated_bucket" {
  source = "./modules/core_s3"
  providers = {
    aws.us_east_1 = aws.us_east_1
    aws.us_east_2 = aws.us_east_2
  }


  bucket_name             = "example"
  enable_versioning       = true
  encrypt_with_kms        = true
  kms_key                 = var.default_s3_kms_key
  replica_kms_key         = aws_kms_key.s3_replica_key.arn
  bucket_acl              = "private"
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
  origin_region           = "us-east-1"
  replica_region          = "us-east-2"
  bucket_policy_json = jsonencode({
    "Id" : "ExamplePolicy",
    "Version" : "2012-10-17",
    "Statement" : [
      {
        "Sid" : "AllowSSLRequestsOnly",
        "Action" : "s3:*",
        "Effect" : "Deny",
        "Resource" : [
          "arn:aws:s3:::example",
          "arn:aws:s3:::example/*"
        ],
        "Condition" : {
          "Bool" : {
            "aws:SecureTransport" : "false"
          }
        },
        "Principal" : "*"
      }
    ]
  })
  tags = var.default_tags
}

Providers

Name Version
aws n/a
aws.us_east_1 n/a
aws.us_east_2 n/a

Resources

Name Type
aws_iam_policy.replication resource
aws_iam_policy_attachment.replication resource
aws_iam_role.replication resource
aws_s3_bucket.this resource
aws_s3_bucket.this_replica resource
aws_s3_bucket_policy.this resource
aws_s3_bucket_policy.this_replica resource
aws_s3_bucket_public_access_block.this resource
aws_s3_bucket_public_access_block.this_replica resource
aws_caller_identity.current data source

Inputs

Name Description Type Default Required
bucket_acl KMS key to use for bucket encryption string n/a yes
bucket_name The Name of the S3 bucket string n/a yes
bucket_policy_json KMS key to use for bucket encryption string n/a yes
enable_versioning Should versioning be enabled on the bucket string n/a yes
encrypt_with_kms Should we use a KMS CMK? If false we will use SSE AES256 string n/a yes
origin_region The Name of the Origin region string n/a yes
replica_region The Name of the Origin region string n/a yes
tags Map to pass in tags to the resources map(string) n/a yes
block_public_acls KMS key to use for bucket encryption bool true no
block_public_policy KMS key to use for bucket encryption bool true no
ignore_public_acls KMS key to use for bucket encryption bool true no
kms_key KMS key to use for bucket encryption string "" no
logging_bucket What bucket should we target for logging? string "" no
logging_enabled Should we enable logging dynamic block? bool false no
logging_prefix What prefix key should we use for logging? string "" no
replica_kms_key KMS key to use for bucket encryption at destiniation string "" no
restrict_public_buckets KMS key to use for bucket encryption bool true no

Outputs

Name Description
arn n/a
domain_name n/a
id n/a
replica_arn n/a
replica_domain_name n/a
replica_id n/a