GithubHelp home page GithubHelp logo

asmtal / tf_aws_tfstate_bucket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bwits/tf_aws_tfstate_bucket

0.0 0.0 0.0 15 KB

create buckets for terraform tfstate files and set cross-region replication.

License: GNU General Public License v3.0

HCL 100.00%

tf_aws_tfstate_bucket's Introduction

terraform state buckets

This is an independent terraform module which need be run before any other terraform commands.

The reason is, we need a s3 bucket to be ready and save terraform tfstate files when initialize a Terraform configuration

Features

  1. terraform configuration files to create terraform state buckets
  2. create source bucket and destination buckets
  3. set cross-region replication on the source bucket.

Set source and destination regions.

Update source and destination regions in variable.tf

S3 bucket name must be globally unique

Currently I use aws account alias name as part of bucket name, you should set postfix to make sure the bucket name is globally unique.

Update bucket postfix name in variable.tf

What is and is not replicated.

What Is and Is Not Replicated

Recommend to enable Amazon S3-Managed Encryption Keys (SSE-S3), but not customer-provided (SSE-C) or AWS KMS–managed encryption (SSE-KMS) keys. Because:

Objects created with server-side encryption using either customer-provided (SSE-C) or AWS KMS–managed encryption (SSE-KMS) keys are not replicated.

Sample backend configuration

terraform init \
-backend=true \
-backend-config="bucket=tf-state" \
-backend-config="key=terraform.tfstate" \
-backend-config="region=eu-west-1" \
-backend-config="acl=bucket-owner-full-control" \
-backend-config="encrypt=1"

Import state

If the tfstate bucket exists, please use below command to import its state after you inited the backend.

terraform import aws_s3_bucket.bucket <exist_bucket_name>

Usage

terraform init
terraform plan
terraform apply

Manually copy the state file to s3 bucket.

After you run terraform plan and terraform apply, a new state file terraform.tfstate is generated, you need manually copy the file to source bucket.

To make sure replicate works, you should see the file has been replicated to bucket <source_bucket>-destination

Reference:

How to Set Up Cross-Region Replication

initialize a Terraform configuration

tf_aws_tfstate_bucket's People

Contributors

bill-newsnow avatar ozbillwang 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.