Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Terraform module that creates a secure S3 bucket with the specified configurations, including options for access logging, custom policies, and additional lifecycle rules.

Notifications You must be signed in to change notification settings

RubenLopSol/Module_s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform module s3 bucket

Terraform module that creates a secure S3 bucket with the specified configurations, including options for access logging, custom policies, and additional lifecycle rules.

Requirements

1. Install Terraform.

2. Ensure you have access to AWS S3 services (and that your AWS profile is configured locally or on your server).

Module Usage

Step 1:

  • To create an S3 bucket, use the code below:

Example:

module "s3-bucket" {
  source                = "git::https://github.com/RubenLopSol/Module_s3.git"
  region                = var.region
  project_name          = var.project_name
  bucket_name           = var.bucket_name
  enable_access_logging = true
  logging_bucket        = var.logging_bucket_name
  logging_bucket_name   = var.logging_bucket_name
  environment           = var.environment

  lifecycle_rules = [
    {
      id      = "delete-old-logs",
      enabled = true,
      prefix  = "logs/",
      expiration = {
        days = 365
      }
    }
  ]
}
  • The logging bucket needs to be created beforehand (must exist).

Step 2: Set the Variables

  • In your variables.tf file, set the variables that the module requires.

Step 3: Initialize & Apply

  • Run terraform init to initialize the Terraform environment and download the module dependencies.
terraform init
  • Apply the configuration to create your S3 bucket by running.
terraform apply

Step 4: Verify Resources

Once the terraform apply completes, your S3 bucket will be created with the following:

  • Logging enabled (if configured).
  • Lifecycle rules applied for the logs folder.

Resources

Name Type
aws_s3_bucket.secure_bucket resource
aws_s3_bucket_lifecycle_configuration.lifecycle resource
aws_s3_bucket_logging.logging resource
aws_s3_bucket_policy.secure_bucket_policy resource
aws_s3_bucket_public_access_block.public_access_block resource
aws_s3_bucket_server_side_encryption_configuration.sse resource
aws_s3_bucket_versioning.versioning resource

Inputs

Name Description Type Default Required
region Value for AWS region string n/a yes
environment Value for tipe of environment string n/a yes
project_name Value for project name string n/a yes
bucket_name Name of the S3 bucket string n/a yes
logging_bucket_name The S3 bucket for storing access logs string null no
custom_bucket_policy Custom policy for the S3 bucket string null no
enable_access_logging Enable access logging for the S3 bucket bool false no
lifecycle_rules Additional lifecycle rules
list(object({
id = string
enabled = bool
prefix = string
expiration = object({
days = number
})
}))
[] no

Outputs

Name Description
bucket_arn ARN of the S3 bucket
bucket_name Name of bucket S3
logging_bucket_name The target bucket for S3 bucket logging

About

Terraform module that creates a secure S3 bucket with the specified configurations, including options for access logging, custom policies, and additional lifecycle rules.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages