Skip to content

A cloudformed terraform remote state using Amazon S3, with locking via DynamoDB

License

Notifications You must be signed in to change notification settings

ndx-video/terraform-remote-state-s3-cloudformation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a Terraform remote state using AWS S3 & DynamoDB.

Deploy

  • Deploy the cloudformation stack in your region (e.g. ap-southeast-2)
    • Deploy the stack make deploy
    • Deploy a managed policy to attach to IAM roles make deploy-policy

Usage

  • Initialise your terraform project to reference the state resources
export accountId=$(aws sts get-caller-identity --query Account --output text)
terraform init \
    -backend-config="region=ap-southeast-2" \
    -backend-config="bucket=terraform-state-${accountId}" \
    -backend-config="key=terraform.tfstate" \
    -backend-config="dynamodb_table=terraform-state"
  • Ensure you reference the state in the terraform project. You can use the workspace_key_prefix to differentiate each project in the state store.
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
  backend "s3" {
    workspace_key_prefix = "my-project"
  }
}

provider "aws" {
  region = "ap-southeast-2"
}

About

A cloudformed terraform remote state using Amazon S3, with locking via DynamoDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 100.0%