Skip to content

Commit

Permalink
⚰️ Remove Terraform useless status steps
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbriere1 committed May 24, 2023
1 parent e5b0a51 commit 3bf87bb
Showing 1 changed file with 3 additions and 78 deletions.
81 changes: 3 additions & 78 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
uses: tailscale/github-action@v1
with:
authkey: ${{ secrets.TAILSCALE_AUTH_KEY }}
version: 1.36.0
version: ${{ vars.TAILSCALE_VERSION }}

- name: Import Secrets
id: secrets
Expand Down Expand Up @@ -89,7 +89,6 @@ jobs:
id: fmt
working-directory: ${{ inputs.workdir || github.workspace }}
run: terraform -chdir=${{ inputs.terraform_dir }} fmt -check
continue-on-error: true

- name: Terraform Init
id: init
Expand All @@ -100,7 +99,6 @@ jobs:
id: validate
working-directory: ${{ inputs.workdir || github.workspace }}
run: terraform -chdir=${{ inputs.terraform_dir }} validate
continue-on-error: true

- name: Terraform Workspace
id: workspace
Expand All @@ -110,82 +108,9 @@ jobs:
- name: Terraform Plan
id: plan
working-directory: ${{ inputs.workdir || github.workspace }}
run: |
terraform -chdir=${{ inputs.terraform_dir }} plan -out=tfplan -no-color -input=false ${{ inputs.terraform_args }}
continue-on-error: true

- name: Publish Terraform summary
run: |
echo "#### Terraform Format and Style 🖌\'${{ steps.fmt.outcome }}\'" >> $GITHUB_STEP_SUMMARY
echo "#### Terraform Initialization ⚙️\'${{ steps.init.outcome }}\'" >> $GITHUB_STEP_SUMMARY
echo "#### Terraform Validation 🤖\'${{ steps.validate.outcome }}\'" >> $GITHUB_STEP_SUMMARY
echo "#### Terraform Plan 📖\'${{ steps.plan.outcome }}\'" >> $GITHUB_STEP_SUMMARY
- name: PR comment Terraform
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style ${{ inputs.terraform_substep_name }}')
})
// 2. Prepare format of the comment
const output = `#### Terraform Format and Style ${{ inputs.terraform_substep_name }} 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Terraform Status
if: steps.plan.outcome == 'failure' || steps.validate.outcome == 'failure' || steps.fmt.outcome == 'failure'
run: exit 1
run: terraform -chdir=${{ inputs.terraform_dir }} plan -out=tfplan -no-color -input=false ${{ inputs.terraform_args }}

- name: Terraform Apply
if: ${{ inputs.terraform_check_only == false }}
working-directory: ${{ inputs.workdir || github.workspace }}
run: |
terraform -chdir=${{ inputs.terraform_dir }} apply -auto-approve -input=false tfplan
run: terraform -chdir=${{ inputs.terraform_dir }} apply -auto-approve -input=false tfplan

0 comments on commit 3bf87bb

Please sign in to comment.