DEVOPS-307 addin terraform workflow #1
This file contains 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
name: Terraform Validation and Format | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
terraform: | |
name: Terraform Validation and Format | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: "1.6.0" | |
- name: Terraform Format | |
id: fmt | |
run: | | |
terraform fmt -recursive | |
continue-on-error: true | |
- name: Check for changes | |
id: changes | |
run: | | |
if git status --porcelain | grep .; then | |
echo "Changes detected" | |
echo "changes_detected=true" >> $GITHUB_OUTPUT | |
else | |
echo "No changes detected" | |
echo "changes_detected=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit and Push Changes | |
if: steps.changes.outputs.changes_detected == 'true' | |
run: | | |
git config user.name 'github-actions' | |
git config user.email 'actions@github.com' | |
git add . | |
git commit -m "Terraform fmt check and update" | |
git push | |
- name: Terraform Init | |
id: init | |
run: terraform init --upgrade | |
- name: Terraform Validate | |
id: validate | |
run: terraform validate |