Skip to content

AWS S3 Backend Module

This module provisions the necessary resources to use an S3 bucket as a Terraform backend.

Resources Created

  • S3 Bucket: Stores the Terraform state files.
  • Versioning enabled.
  • Server-side encryption (AES256) enabled.
  • Public access blocked.

Usage

module "terraform_state_backend" {
  source = "./modules/aws/s3"

  bucket_name         = "my-terraform-state-bucket"

  tags = {
    Environment = "Dev"
    Project     = "Infrastructure"
  }
}

Inputs

Name Description Type Default Required
bucket_name The name of the S3 bucket to store the Terraform state. string "isre-devops-terraform-state" no
region The AWS region to deploy the resources in. string "us-east-1" no
state_key The path (key) within the S3 bucket to store the state file. string "global/s3/terraform.tfstate" no
tags A map of tags to add to all resources. map(string) {} no

Outputs

Name Description
s3_bucket_arn The ARN of the S3 bucket

Switching Between Terraform and OpenTofu

Terragrunt allows you to dynamically choose the underlying binary (Terraform or OpenTofu) using either a CLI flag or an environment variable.

Set the TERRAGRUNT_TFPATH variable to the desired binary name or path:

# To use OpenTofu
export TERRAGRUNT_TFPATH=tofu
terragrunt plan

# To use Terraform
export TERRAGRUNT_TFPATH=terraform
terragrunt plan

Option 2: CLI Flag

Pass the --terragrunt-tfpath flag directly to the command:

# To use OpenTofu
terragrunt plan --terragrunt-tfpath tofu

# To use Terraform
terragrunt plan --terragrunt-tfpath terraform