Skip to content

Instantly share code, notes, and snippets.

@TheMagoo73
Created August 6, 2019 14:17
Show Gist options
  • Save TheMagoo73/6bdc9296d8d7e65335018b731436d84b to your computer and use it in GitHub Desktop.
Save TheMagoo73/6bdc9296d8d7e65335018b731436d84b to your computer and use it in GitHub Desktop.
CircleCI definition for a Terraform deployment
version: 2
defaults: &defaults
working_directory: ~/repo
docker:
- image: gumshoe/cci-terraform:0.0.1-alpha
environment:
TF_IN_AUTOMATION: true
GOOGLE_APPLICATION_CREDENTIALS: ~/repo/terraform-deploy.json
jobs:
init:
<<: *defaults
steps:
- checkout
- run:
name: gcp auth
command: echo $GCP_CREDENTIALS > terraform-deploy.json
- run:
name: init
command: terraform init -input=false
- persist_to_workspace:
root: ~/repo
paths: .
plan:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: plan
command: terraform plan -no-color -out=tfplan -input=false
- store_artifacts:
path: ~/repo/tfplan
destination: tfplan
- persist_to_workspace:
root: ~/repo
paths: .
apply:
<<: *defaults
steps:
- attach_workspace:
at: ~/repo
- run:
name: apply
command: terraform apply -input=false -auto-approve tfplan
- run:
name: show
command: terraform show -no-color > tfresult
- store_artifacts:
path: ~/repo/tfresult
destination: tfresult
workflows:
version: 2
build_deploy:
jobs:
- init
- plan:
requires:
- init
- apply:
requires:
- plan
filters:
branches:
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment