Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien HOUZÉ committed Jan 3, 2021
0 parents commit 954de9f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Review terraform plan

Run and cleanup terraform plan output, store it into an output to allow reviewing it
## Inputs
### `terraform-environment`

**Required** Terraform environment, used to load corresponding var file named `<terraform-environment>.tfvars`
into the working directory. Default `"preproduction"`.
### `working-directory`

**Required** Working directory where terraform plan is executed. Default `"."`.

## Example usage


Here

```yaml
- uses: gogaille/review-terraform-plan
id: terraform-plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
with:
terraform-environment: 'preproduction'
working-directory: 'infrastructure'

- uses: phulsechinmay/rewritable-pr-comment@v0.3
with:
message: ${{ steps.terraform-plan.outputs.plan-details }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_IDENTIFIER: 'terraform-plan-output'
```
61 changes: 61 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Review terraform plan
description: >
Run and cleanup terraform plan output, store it into an output to allow reviewing it.
inputs:
terraform-environment:
description: >
Terraform environment, used to load corresponding var file named
<terraform-environment>.tfvars into the working directory.
required: true
default: "preproduction"
working-directory:
description: working directory
required: true
default: "."

outputs:
plan-details:
description: >
Clean terraform plan, in HTML format, ready to integrate in a comment of
corresponding pull request.
value: ${{ steps.plan.outputs.plan-details }}

runs:
using: "composite"
steps:
- id: plan
name: terraform plan for review
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
plan=$(terraform plan -lock=false -no-color -var-file=${{ inputs.terraform-environment }}.tfvars)
title=$(echo -e "$plan" | grep -e '^Plan:' | sed -E 's|Plan:||')
# remove plan noise
plan=$(
echo -e "$plan" | \
tail -n +$(
echo -e "$plan" | \
grep -nE 'Terraform will perform the following actions|No changes. Infrastructure is up-to-date' | \
cut -d':' -f1
)
)
message=$(printf "
<details>
<summary><b>Terraform plan:</b> %s %s</summary>
\`\`\`hcl
%s
\`\`\`
</details>
" "${title:-No changes. Infrastructure is up-to-date.}" "$(git rev-parse --short $GITHUB_SHA)" "$plan")
message="${message//'%'/'%25'}"
message="${message//$'\n'/'%0A'}"
message="${message//$'\r'/'%0D'}"
echo -e "$plan"
echo ""
echo ::set-output name=plan-details::"$message"

0 comments on commit 954de9f

Please sign in to comment.