Skip to content

Create a new project

Before proceeding make sure that you have followed the Installation.

Configure direnv

For direnv to work properly it needs to be hooked into the shell. Check direnv docs to know more: https://direnv.net/docs/hook.html

Make sure that you have followed direnv documentation before proceeding.

Configure Terrabutler

Create your project folder

mkdir <project_name>

Download Template

Start by downloading the Terrabutler Template Project from the repository source below:

Version-shield

Copy the files inside ./terrabutler-template/ to the root of your project folder.

$ cp -a /terrabutler-template/. /<project_name>/

Create a new workspace

Before configuring terrabutler, inside <project_name>/site_inception folder, you will need to create a Terraform Workspace: For example, we are gonna call it "staging"

$ cd site_inception
$ terraform workspace new staging

Change Variables

Run the script ./<project_name>/config_template.sh, with the following arguments, located inside the project folder root:

$ ./config_template.sh -d <domain> -e <environment_name> -p <project_name>

USAGE:
   ./config_template [FLAG] [STRING]

FLAGS:
   -o <organization_name>   The name for your organization.  
                            Example: -o example

   -d <domain>              The domain of your organization. 
                            Example: -d example.com

   -e <environment_name>    The environment name of your organization. 
                            Example: -e staging
Danger

This script only works with the template folder! Don't use it in another project folders! ./terrabutler-template/config_template.sh

Terraform

Start by installing Terraform with tfenv:

$ tfenv install 

Initialize the Project

Perform an Terraform Initialization inside site_inception:

$ cd /site_inception/
$ terraform init
Perform an Terraform Apply with the .tfvars inside /config/variables/:

./configs/variables/global.tfvars
./configs/variables/<project_name>-<environment_name>.tfvars"
./configs/variables/<project_name>-<environment_name>-inception.tfvars"

$ terraform apply -var-file="../configs/variables/global.tfvars" -var-file="../configs/variables/<project_name>-<environment_name>.tfvars" -var-file="../configs/variables/<project_name>-<environment_name>-inception.tfvars"

Change local to remote backend

Uncomment the remote backend line

Remove the commented line as below, in the terrabutler-template in the path ./site-inception/terraform.tf to change from local to remote.

backend "s3" {}

Perform an Terraform initialization with the backend config file,located in /configs/backend/ to update the new changes:

$ terraform init -backend-config=<inception_backend_path>  
Tip

Example: $ terraform init -backend-config="./configs/backends/--inception.tfvars"

Delete the local state

Delete the local state in /site_inception, as it is not necessary:

$ rm -rf terraform.tfstate.d/ terraform.tfstate terraform.tfstate.backup

Terrabutler commands

Terrabutler Plan

Perform an Terrabutler Plan to ensure everything is ok, and plan any changes:

$ terrabutler tf -site inception plan

Terrabutler Apply

Perform an Terrabutler Apply to apply the planned changes:

$ terrabutler tf -site inception apply

Terrabutler Destroy

Perform an Terrabutler Destroy to delete or undo any changes made in the provider:

$ terrabutler tf -site inception destroy