Skip to main content

Amazon S3

Overview

The AWS S3 Module provides a reusable and scalable way to provision and manage Amazon Simple Storage Service (S3) buckets using Terraform.
It abstracts the complexity of configuring S3 resources and enables developers to define infrastructure with minimal effort while following best practices.

This module supports both resource creation and data sources for managing S3 buckets, policies, and objects in a consistent and modular way.


Features

  • 🚀 Reusable & Modular – Predefined structure for resources and data modules.
  • 🔐 Security Best Practices – Supports bucket policies, ACLs, and access control.
  • 🗂 Lifecycle Management – Configure bucket lifecycle rules to manage data efficiently.
  • 📜 Logging & Versioning – Enable bucket logging and versioning for compliance.
  • 🌐 CORS Support – Manage cross-origin resource sharing rules.
  • 🧩 Extensible – Easy to integrate with other Terraform modules and AWS services.

Core Concepts

  1. Resources Module

    • Creates and manages S3 buckets and related configurations.
    • Includes support for:
      • Bucket ACLs
      • Bucket policies
      • Versioning
      • Lifecycle rules
      • Logging
      • CORS configuration
  2. Data Module

    • Allows fetching information about existing S3 resources.
    • Useful for referencing bucket attributes and integrating with other infrastructure components.
  3. Objects Management

    • Supports defining and uploading objects to S3 buckets.
    • Provides flexibility for managing data storage within buckets.
  4. Separation of Concerns

    • resources/ handles bucket creation and configuration.
    • data/ is focused on reading and referencing existing S3 resources.
    • This separation ensures clarity, reusability, and modular design.

Sample Usage

# DEPLOY ANANTA CLOUD'S S3 MODULE

module "s3_bucket" {
source = "github.com/anantacloud/terraform-aws-s3-module/modules/resources"

# ==========================
# REQUIRED VARIABLES
# ==========================
bucket = "my-app-bucket"
acl = "private"

# ==========================
# OPTIONAL VARIABLES
# ==========================
versioning = {
enabled = true
}

logging = {
target_bucket = "my-log-bucket"
target_prefix = "logs/"
}

cors_rules = [
{
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
]

tags = {
Environment = "dev"
Project = "my-app"
}
}

Required

NameDescriptionTypeExample
bucketName of the S3 bucketstring"my-app-bucket"
aclAccess control list for the bucketstring"private"

Optional

NameDescriptionTypeDefault
versioningEnable bucket versioningobjectfalse
loggingConfigure bucket loggingobjectnull
cors_rulesDefine CORS configuration for the bucketlist[]
tagsAdd custom tags to the bucketmap{}