Skip to content

Instantly share code, notes, and snippets.

@Spazzy757
Last active October 21, 2021 06:09
Show Gist options
  • Save Spazzy757/93ecaa27e1bb7af361e35d9bcfaa8c42 to your computer and use it in GitHub Desktop.
Save Spazzy757/93ecaa27e1bb7af361e35d9bcfaa8c42 to your computer and use it in GitHub Desktop.
name: stg
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
plan:
runs-on: ubuntu-latest
container:
image: $IMAGE
env:
TF_WORKSPACE: stg
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TF_IN_AUTOMATION: true
steps:
- name: checkout code
uses: actions/checkout@v2
# Terraform plan and output to file
- name: plan
id: plan
run: |
terraform plan \
--out=tfplan \
-no-color \
--input=false
# Set Plan to ENV as step outputs dont support multiline
- name: show
id: show
run: |
export CHANGES="$(terraform show -no-color tfplan)"
echo "CHANGES<<EOF" >> $GITHUB_ENV
echo "$CHANGES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Used to add the plan to the pull requests
- name: comment pull request
if: github.event_name == 'pull_request'
uses: actions/github-script@0.9.0
env:
PLAN: ${{ env.CHANGES }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `
Terraform Output Results for Run
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
`
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment