Skip to content

Remote Terraform States in AWS S3 made easy (includes automatic backend configuration generation)

License

Notifications You must be signed in to change notification settings

ansraliant/terraform-aws-s3-state

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Remote State Config Module

This module creates a bucket to hold the remote state files of terraform, a dynamo db table for the locks and automatically generates backend configuration files.

How to Use

You will need a main.tf to call this module with the correct parameters.

Simple Example

To use this module out-of-the-box, without changing the default behaviour

provider "aws" {
  region = "ap-northeast-1"
}

module "remote_state" {
  source = "ansraliant/s3-state/aws"

  bucket_name    = "mybucket"
  dynamodb_table = "mydynamodb"
  states         = { infra = "../backend.tf.json" }
}

Advanced Config Example

How to use with advanced config

locals {
  prefix  = "myproject"
  profile = "my-aws-profile"
  region  = "ap-northeast-1"

  states = {
    infra = "../backend.tf.json"
    auth  = "../auth/backend.tf.json"
  }

  bucket_name    = "${local.prefix}-${substr(md5(data.aws_caller_identity.this.account_id), 0, 16)}"
  dynamodb_table = local.prefix
}

data "aws_caller_identity" "this" {}

provider "aws" {
  profile = local.profile
  region  = local.region
}

module "remote_state" {
  source  = "ansraliant/s3-state/aws"

  profile        = local.profile
  bucket_name    = local.bucket_name
  dynamodb_table = local.dynamodb_table
  states         = local.states
}

You can either hardcode, use tfvars, whatever works for you

About

Remote Terraform States in AWS S3 made easy (includes automatic backend configuration generation)

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages