Skip to content

Terraform

Terraform #2

Workflow file for this run

# This workflow runs on `pull_request`.
#
# `Terraform` job uses `checkout` to download the content of the repository. It installs the latest version of Terraform CLI
# It uses the GitHub Action `GitHubAction_terraform-fmt` to run `terraform fmt`. If change are made to the code, the code is push
# to the branch.
#
# Documentation
# - https://github.com/actions/checkout
# - https://github.com/benyboy84/GitHubAction_terraform-fmt
#
name: Terraform
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
permissions:
contents: write
pull-requests: write
jobs:
terraform:
name: Terraform
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Branch
id: branch
run: echo "branch=${GITHUB_HEAD_REF}" >> "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.branch.outputs.branch }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
- name: Terraform Format
id: fmt
uses: benyboy84/GitHubAction_terraform-fmt@v1
with:
check: false
recursive: true
comment: true
- name: Git Push
if: ${{ steps.fmt.outputs.exitcode == 3 }}
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
git add -A
git commit -m "Automated Terraform Formatting"
git push -u origin ${{ steps.branch.outputs.branch }}
echo "Terraform file(s) has been formatted and pushed to the repository."