Created
July 9, 2020 01:26
-
-
Save nicksantamaria/67dc8484bce431431b29eba89d1bc1e0 to your computer and use it in GitHub Desktop.
Terraform CircleCI Workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
jobs: | |
plan: | |
docker: | |
- image: hashicorp/terraform:latest | |
working_directory: /code | |
steps: | |
- checkout | |
- run: | |
name: Init | |
command: terraform init -input=false | |
- run: | |
name: Plan | |
command: terraform plan -input=false -out=tfplan -no-color | |
- run: | |
name: Render plan for PR comment | |
command: terraform show -no-color tfplan > tfplan.txt | |
- persist_to_workspace: | |
root: /code | |
paths: | |
- . | |
apply: | |
docker: | |
- image: hashicorp/terraform:latest | |
working_directory: /code | |
steps: | |
- attach_workspace: | |
at: /code | |
- run: | |
name: Apply | |
command: terraform apply tfplan | |
plan_comment: | |
docker: | |
- image: cloudposse/github-commenter:latest | |
working_directory: /code | |
steps: | |
- checkout | |
- attach_workspace: | |
at: /code | |
- run: | |
name: Post plan to PR comment | |
command: |- | |
export CIRCLE_PR_NUMBER=${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}} | |
if [ -z $CIRCLE_PR_NUMBER ]; then echo "Not a pull request - aborting"; exit 0; fi | |
cat /code/tfplan.txt | github-commenter \ | |
-owner ${CIRCLE_PROJECT_USERNAME} \ | |
-repo ${CIRCLE_PROJECT_REPONAME} \ | |
-number $CIRCLE_PR_NUMBER \ | |
-delete-comment-regex "Output from" \ | |
-type pr \ | |
-template_file /code/.circleci/plan-comment.tpl | |
workflows: | |
version: 2 | |
plan_pr: | |
jobs: | |
- plan | |
- plan_comment: | |
requires: | |
- plan | |
filters: | |
branches: | |
ignore: master | |
- apply: | |
requires: | |
- plan | |
filters: | |
branches: | |
only: master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output from `terraform plan` | |
``` | |
{{.}} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment