Giter Club home page Giter Club logo

multiple-envs's Introduction

Multiple Environments in Terraform

This is an example repository of Terraform code showing how to deploy and revert infrastructure changes for multiple environments with Terraform Enterprise & GitHub.

Setup

To setup a multi-environment deployment workflow, create a new Terraform Enterprise environment for each.

  1. Fork the hashicorp/multiple-envs repo
  2. Link your Atlas account to GitHub
  3. Use the Import tool to create new environments for demo-dev, demo-staging, and demo-prod
  • Name the environment: demo-dev, demo-staging, or demo-prod depending on the environment you're creating
  • GitHub repository: multiple-envs
  1. Go to Variables in the left navigation of each environment
  • Add the below Environment Variables
    • AWS_ACCESS_KEY_ID: YOUR_AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY: YOUR_AWS_SECRET_ACCESS_KEY
    • AWS_DEFAULT_REGION: us-east-1
  • Add the below Terraform Variables to override the defaults to be environment specific - name: demo-dev, demo-staging, or demo-prod depending on the environment you're creating - The placeholder variables allow you to remove environment specific or secret/sensitive variables from version control
  1. Click Queue plan and Confirm & apply for each environment to deploy the infrastructure

Deployment Workflow

Below is an example deployment workflow you can use to version changes through each environment in a collaborative way.

  1. Create and push a feature branch with a proposed change, for example, adding a new tag to the security group in network.tf
  2. Create a pull request for your feature branch against master
  • You should see 3 Terraform plan checks that have changes
  1. Deploy your feature branch to demo-dev
  • Go to Integrations in the left navigation of the demo-dev environment and enter your feature branch name into GitHub branch, then click Update GitHub settings
  • This will automatically trigger a plan that you can Confirm & Apply in Runs to deploy
  1. Deploy your feature branch to demo-staging
  • Go to Integrations in the left navigation of the demo-staging environment and enter your feature branch name into GitHub branch, then click Update GitHub settings
  • This will automatically trigger a plan that you can Confirm & Apply in Runs to deploy
  1. Deploy your feature branch to demo-prod now that you've tested the change in demo-dev and demo-staging
  • Merge your pull request
  • This will trigger a Terraform plan in Runs of the demo-prod environment that you can Confirm & Apply to deploy
  1. Remove your feature branch from GitHub branch in Integrations of demo-dev and demo-staging and click Update GitHub settings, there should be no changes

Revert Workflow

In the event that one of your commits should need to be reverted, you can follow the below steps to achieve this.

  1. Go to Runs in the left navigation of the demo-prod environment and click on the run that you would like to revert
  2. On the top right, click the Git SHA link that triggered this run
  3. In GitHub, navigate to the PR that was associated with this commit and click Revert
  4. Create a pull request to revert the change, this should have Terraform plan change checks across all 3 environments
  5. Upon success of the Terraform plan checks, merge the pull request
  6. This will trigger a Terraform plan in all 3 environments that you can Confirm & Apply to revert the change

multiple-envs's People

Contributors

bensojona avatar calebalbers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.