Home

Awesome

Terraform Rake Tasks

Rake tasks for managing Terraform with shared S3 State.

Usage

Gemfile

gem 'terraform-rake-tasks', git: 'https://github.com/gina-alaska/terraform-rake-tasks'

Rakefile

require 'terraform-rake-tasks/tasks'

TerraformRakeTasks::Tasks.load_tasks!

Configuration

This gem uses the following ENV variables:

Variable Namepurposedefault
TF_PROJECTName of the terraform project. Should be set to prevent name collisionstf
TF_ENVTerraform Environment. Used for multi-environment repositories.dev
AWS_PROFILEName of AWS Profile to usedefault
S3_BUCKETName of S3 Bucket to store shared data in** NO DEFAULT **
SSH_KEY_PATHPath to store ssh credentials$HOME/.terraform/ssh

Rake tasks provided

rake apply          # Apply Terraform Plan
rake bootstrap      # Bootstrap terraform running environment from scratch
rake destroy        # Run 'terraform destroy'
rake dotenv         # Load environment settings from .env
rake get            # Run 'terraform get'
rake graph          # Generate dependenecy graph
rake init           # Initializes terraform remote state
rake keys:fetch     # Fetch new ssh keys from AWS
rake keys:generate  # Generate new ssh keys (DANGER: Will cause existing resources to be rebuilt)
rake keys:rotate    # Rotate ssh keys (DANGER: Will cause existing resources to be rebuilt)
rake keys:upload    # Upload keys to S3
rake plan           # Run 'terraform plan'
rake show           # Run 'terraform show'

rake bootstrap

Terraforming

After the bootstrap your usage is via rake as a thin wrapper around terraform plan, get, show, and destroy commands. You can skip that if you source the .env to allow running of terraform directly. (Just don't go wandering about into other environments after that).