Thin wrapper for managing terraform workspaces
Find a file
2019-04-15 15:15:39 +02:00
.circleci Atmos v.1 2019-04-10 12:00:01 +02:00
.gitignore Initial commit 2019-04-09 16:54:28 +02:00
atmos.py Add -t flag to use environment vars to generate credetials file. 2019-04-15 15:15:39 +02:00
Dockerfile Remove atmos config from dockerfile 2019-04-10 14:14:20 +02:00
README.md Changed docs 2019-04-10 15:41:36 +02:00
shared-creds Add documentation 2019-04-10 14:00:09 +02:00

CircleCI

Terraform Atmosphere

Atmos is a thin wrapper for managing Terraform Workspaces easily. Using the workspace name it will select the correct .tfvar file, defaulting to a qa var file for any other workspace. This is primarily for pipelines but works just as well from the command line. It can process all terraform commands and parameters passing them on directly.

Quick Start

  • Build the atmos image
  • Use atmos as the build image in your CI/CD
  • Include switching/creating terraform workspaces
  • Use $ atmos apply/plan/destroy to run terraform apply whilst maintaining environment context

Directory structure

Atmos requires the following file structure

├── main.tf
├── variables.tf
└── vars
    ├── dev.tfvars
    ├── preprod.tfvars
    ├── prod.tfvars
    └── qa.tfvars

The vars directory is scanned by atmos and matches the current workspace to the vars file. If the workspace is not found it defaults to the qa environment. This is to ensure qa branches are deployed similarily without having to create a var file for each new branch.

AWS Credentials

To get the most out of Terraform workspaces it is recommended that the AWS provider uses the profile attribute.

# main.tf
provider "aws" {
    region = "${var.region}"
    profile = "${var.workspace}"
}
# variables.tf
variable "workspace" {
    type = "string"
    default = "default"
}

This will make Terraform lookup AWS credentials from the ~/.aws/credentials file using the workspace name as the stanza name. For example the credentials file would look like the shared-creds file in this repo.