Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Terraform module to create default S3 bucket with logging and encryption type specific features.

License

Notifications You must be signed in to change notification settings

grupoboticario/terraform-aws-s3

 
 

Repository files navigation

ARCHIVED!!! ARCHIVED!!!

THIS REPOSITORY IS ARCHIVED AND NO LONGER MAINTAINED.

PLEASE USE A NEW ONE: https://github.com/grupoboticario/tf-aws-module-s3

Terraform AWS S3

Terraform module to create default S3 bucket with logging and encryption type specific features.

Terraform Licence


We eat, drink, sleep and most importantly love DevOps. We are working towards stratergies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy Bigger problems are always solved by breaking them into smaller manageable problems. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller connected yet manageable pieces within the infrastructure.

This module is basically combination of Terraform open source and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.

We have fifty plus terraform modules. A few of them are comepleted and are available for open source usage while a few others are in progress.

Prerequisites

This module has a few dependencies:

Examples

IMPORTANT: Since the master branch used in source varies based on new modifications, we suggest that you use the release versions here.

Here are some examples of how you can use this module in your inventory structure:

Basic Bucket

module "s3" {
  source  = "app.terraform.io/grupoboticario-AWS/s3/aws"
  version = "0.12.4"
  environment    = var.environment
  application    = var.application
  name           = "bucket name"
  acl            = "private"
}

Encryption Bucket

module "s3" {
  source  = "app.terraform.io/grupoboticario-AWS/s3/aws"
  version = "0.12.4"
  environment    = var.environment
  application    = var.application
  encryption_enabled = true
  versioning          = true
  sse_algorithm       = "AES256"
  name           = "bucket name"
  acl            = "private"
}

Logging Bucket

module "s3-documents" {
  source  = "app.terraform.io/grupoboticario-AWS/s3/aws"
  version = "0.12.4"
  environment    = var.environment
  application    = var.application
  encryption_enabled = true
  versioning          = true
  sse_algorithm       = "AES256"
  name           = "bucket name"
  acl            = "private"
  bucket_logging_enabled  = true
  target_bucket           = "bucket-logs12"
  target_prefix           = "logs"
}

Website Host Bucket

module "s3-documents" {
  source  = "app.terraform.io/grupoboticario-AWS/s3/aws"
  version = "0.12.4"
  environment    = var.environment
  application    = var.application
  encryption_enabled = true
  versioning          = true
  sse_algorithm       = "AES256"
  name           = "bucket name"
  acl            = "private"
  website_hosting_bucket              = true
  website_index                       = "index.html"
  website_error                       = "error.html"
  bucket_policy                       = true
  lifecycle_expiration_enabled        = true
  lifecycle_expiration_object_prefix  = "test"
  lifecycle_days_to_expiration        = 10
  aws_iam_policy_document             = data.aws_iam_policy_document.default.json
}
data "aws_iam_policy_document" "default" {
  version = "2012-10-17"
  statement {
       sid = "Stmt1447315805704"
       effect = "Allow"
       principals {
            type = "AWS"
            identifiers = ["*"]
          }
       actions = ["s3:GetObject"]
       resources = ["arn:aws:s3:::test-website-bucket-clouddrove/*"]
   }
}

Inputs

Name Description Type Default Required
acl Canned ACL to apply to the S3 bucket. string `` no
application Application (e.g. cd or clouddrove). string `` no
attributes Additional attributes (e.g. 1). list <list> no
aws_iam_policy_document Specifies the number of days after object creation when the object expires. string `` no
bucket_enabled Enable simple S3. bool true no
bucket_logging_enabled Enable logging of S3. bool false no
bucket_policy Conditionally create S3 bucket policy. bool false no
create_bucket Conditionally create S3 bucket. bool true no
delimiter Delimiter to be used between organization, environment, name and attributes. string - no
encryption_enabled Enable encryption of S3. bool false no
environment Environment (e.g. prod, dev, staging). string `` no
force_destroy 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
kms_master_key_id The AWS KMS master key ID used for the SSE-KMS encryption. This can only be used when you set the value of sse_algorithm as aws:kms. The default aws/s3 AWS KMS master key is used if this element is absent while the sse_algorithm is aws:kms. string `` no
label_order Label order, e.g. name,application. list <list> no
lifecycle_days_to_expiration Specifies the number of days after object creation when the object expires. number 365 no
lifecycle_days_to_glacier_transition Specifies the number of days after object creation when it will be moved to Glacier storage. number 180 no
lifecycle_days_to_infrequent_storage_transition Specifies the number of days after object creation when it will be moved to standard infrequent access storage. number 60 no
lifecycle_expiration_enabled Specifies expiration lifecycle rule status. bool false no
lifecycle_expiration_object_prefix Object key prefix identifying one or more objects to which the lifecycle rule applies. string `` no
lifecycle_glacier_object_prefix Object key prefix identifying one or more objects to which the lifecycle rule applies. string `` no
lifecycle_glacier_transition_enabled Specifies Glacier transition lifecycle rule status. bool false no
lifecycle_infrequent_storage_object_prefix Object key prefix identifying one or more objects to which the lifecycle rule applies. string `` no
lifecycle_infrequent_storage_transition_enabled Specifies infrequent storage transition lifecycle rule status. bool false no
name Name (e.g. app or cluster). string `` no
sse_algorithm The server-side encryption algorithm to use. Valid values are AES256 and aws:kms. string AES256 no
tags Additional tags (e.g. map(BusinessUnit,XYZ). map <map> no
target_bucket The name of the bucket that will receive the log objects. string `` no
target_prefix To specify a key prefix for log objects. string `` no
versioning Enable Versioning of S3. bool false no
website_error An absolute path to the document to return in case of a 4XX error. string error.html no
website_hosting_bucket Enable website hosting of S3. bool false no
website_index Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders. string index.html no

Outputs

Name Description
arn The ARN of the s3 bucket.
bucket_domain_name The Domain of the s3 bucket.
id The ID of the s3 bucket.
tags A mapping of tags to assign to the resource.

Testing

In this module testing is performed with terratest and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a GO environment in your system.

You need to run the following command in the testing folder:

  go test -run Test

Feedback

If you come accross a bug or have any feedback, please log it in our issue tracker, or feel free to drop us an email at hello@clouddrove.com.

If you have found it worth your time, go ahead and give us a * on our GitHub!

About us

At CloudDrove, we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.

We are The Cloud Experts!


We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.

About

Terraform module to create default S3 bucket with logging and encryption type specific features.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 79.5%
  • Go 20.1%
  • Makefile 0.4%