Running terraform scripts

Overview

Terraform is a great provisioning platform and allows you to specify variables that can be read from the environment or from file.

The easiest way to use pk with terraform is to create an environment entry.

Example

Create an environment with your AWS credentials.

TF_VAR_access_key=<Your aws creds key here>
TF_VAR_secret_key=<Your aws creds secret here>

Call it terraform-env.

Remember that terraform reads its variables from the environment with TF_VAR_<var_name>

Now you can run your terraform using:

pk sh --safe mysafe --lbls terraform-env terraform plan

And you should see it running:

provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Default: us-east-1
  Enter a value:

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

You can also create a bash alias.
I normally put the following in my ~/.zshrc file:

alias tf-dev='pk sh -s mysafe -n terraform-env terraform'

Now everytime you need to run it just type:

tf-dev plan
#or tf-dev apply