Git Product home page Git Product logo

terraform-backend-aws's Introduction

terraform-backend-setup-aws

Set up S3 bucket and DynamoDB table to use for Terraform State Store and Locking.

Usage

There is one required variable, bucket_name, that needs to be set. It can be set using terraform apply -var=bucket_name=my-terraform-bucket or using a .tfvars file.

There are a few optional variables, like aws_region, encrypt and workspace_key_prefix. An example .tfvars file:

aws_region = "us-east-1"
bucket_name = "my-terraform-bucket"
encrypt = true
workspace_key_prefix = "terraform"

Plan

To see what will be created you can run:

terraform plan -var=bucket_name=my-terraform-bucket

or

terraform plan -var-file=./myvars.tfvars

Note: Terraform variable files .tfvars named terraform.tfvars or *.auto.tfvars are automatically used without using the "-var-file" argument.

Apply

To create the resources run:

terraform apply -var=bucket_name=my-terraform-bucket

or

terraform apply -var-file=./myvars.tfvars

Generate

Once the resources have been created you can generate the backend configuration to use with other Terraform projects.

make generate

Copy the output and save it or redirect to a file.

# Redirect output directly to a file
make generate > backend.tf

# MacOS copy the output to clipboard
make generate | bpcopy

Backup

Since this terraform is meant to be used for the initalization of a backend S3 bucket for (other) terraform we don't expect this state to have a remote backend itself. Therefore it would be a good idea to back up the state manually, we can even copy it to the bucket we just created. But any remote location should be fine.

Using awscli we can copy the variable and state files to the bucket:

aws s3 cp myvars.tfvars s3://my-terraform-bucket/backup/terraform-backend/
aws s3 cp terraform.state s3://my-terraform-bucket/backup/terraform-backend/

To fetch the state at a later time:

aws s3 cp s3://my-terraform-bucket/backup/terraform-backend/myvars.tfvars ./
aws s3 cp s3://my-terraform-bucket/backup/terraform-backend/terraform.tfstate ./

terraform-backend-aws's People

Contributors

allir avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.