Giter Site home page Giter Site logo

tkahng / terraform-remote-state Goto Github PK

View Code? Open in Web Editor NEW

This project forked from turnerlabs/terraform-remote-state

0.0 0.0 0.0 23 KB

A Terraform module that configures an s3 bucket for use with Terraform's remote state feature

License: Other

HCL 100.00%

terraform-remote-state's Introduction

terraform-remote-state

Current release: v5.2.0

A Terraform module that configures an s3 bucket for use with Terraform's remote state feature.

Useful for creating a common bucket naming convention and attaching a bucket policy using the specified role.

The way S3 buckets are described in Terraform changed significantly with version 4.0.0 of the AWS provider, which corresponds to the v5.0.0 tag of this module. Be sure to use a previous version of the module (the immediately-prior one is v4.0.2) if you are using an older version of the AWS provider. In general it's a good idea always to reference the module with an explicit ?ref=_tag_ in the URL and commit the .terraform.lock.hcl file created by terraform init alongside your source code.

Inputs

Name Description Type Default Required
application the application that will be using this remote state string - yes
block_public_access ensure bucket access is "Bucket and objects not public" bool true no
multipart_days string 3 no
multipart_delete incomplete multipart upload deletion string true no
role the primary role that will be used to access the tf remote state string - yes
additional_roles additional roles that will be granted access to the remote state list of strings [] no
dynamodb_state_locking if enabled, creates a dynamodb table to be used to store state lock status bool false no
tags tags to apply the created S3 bucket map - yes

Outputs

Name Description
bucket the created bucket
dynamodb_lock_table name of dynamodb lock table, if created

usage example

setup the remote state bucket

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = ">= 4.0.0"
    }
  }
}

module "tf_remote_state" {
  source = "github.com/turnerlabs/terraform-remote-state?ref=v5.2.0"

  role          = "aws-ent-prod-devops"
  application   = "my-test-app"

  tags = {
    team            = "my-team"
    "contact-email" = "[email protected]"
    application     = "my-app"
    environment     = "dev"
    customer        = "my-customer"
  }
}

output "bucket" {
  value = module.tf_remote_state.bucket
}
$ terraform init
$ terraform apply

Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:
bucket = tf-state-my-test-app

Now configure your script to use the remote state bucket. Note that you need to be logged in to the specified role in order to apply your scripts.

terraform {
  backend "s3" {
    region  = "us-east-1"
    bucket  = "tf-state-my-test-app"
    key     = "dev.terraform.tfstate"
  }
}
dynamodb state locking

Terraform S3 backend allows you to define a dynamodb table that can be used to store state locking status. To create and use a table set dynamodb_state_locking to true.

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = ">= 4.0.0"
    }
  }
}

module "tf_remote_state" {
  source = "github.com/turnerlabs/terraform-remote-state?ref=v5.1.0"

  role                   = "aws-ent-prod-devops"
  application            = "my-test-app"
  dynamodb_state_locking = "true"

  tags = {
    team            = "my-team"
    "contact-email" = "[email protected]"
    application     = "my-app"
    environment     = "dev"
    customer        = "my-customer"
  }
}

output "bucket" {
  value = module.tf_remote_state.bucket
}

output "bucket" {
  value = module.tf_remote_state.dynamodb_lock_table
}
$ terraform init
$ terraform apply

Apply complete! Resources: 7 added, 0 changed, 0 destroyed.

Outputs:

bucket = "tf-state-my-test-app"
dynamodb_lock_table = "tf-state-lock-my-test-app"

Now configure your script to use the remote state bucket and lock table. Note that you need to be logged in to the specified role in order to apply your scripts.

terraform {
  backend "s3" {
    region         = "us-east-1"
    bucket         = "tf-state-my-test-app"
    key            = "dev.terraform.tfstate"
    dynamodb_table = "tf-state-lock-my-test-app"
  }
}

terraform-remote-state's People

Contributors

mjreed-wbd avatar jritsema avatar riyadchowdhury avatar awlawl avatar ajliv avatar jkurz 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.