Files
a13labs.infra/.github/workflows/terraform-iac-validate-on-pr.yml
T

61 lines
1.8 KiB
YAML

name: Terraform IAC Validate on Pull Request
on:
pull_request:
branches:
- main
paths:
- "terraform/iac/**"
types:
- opened
- synchronize
- reopened
jobs:
terraform-validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Setup Ansible environment
uses: ./.github/actions/setup-ansible-env
with:
project-id: ${{ secrets.BW_PROJECT_ID }}
organization-id: ${{ secrets.BW_ORGANIZATION_ID }}
access-token: ${{ secrets.BW_ACCESS_TOKEN }}
ansible-user: ${{ secrets.ANSIBLE_USER }}
host-group: iac
- name: Get Host Info
uses: ./.github/actions/get-host-info
id: get-host-info
with:
project-id: ${{ secrets.BW_PROJECT_ID }}
organization-id: ${{ secrets.BW_ORGANIZATION_ID }}
access-token: ${{ secrets.BW_ACCESS_TOKEN }}
ansible-user: ${{ secrets.ANSIBLE_USER }}
target-host: iac
- name: Setup Terraform environment
uses: ./.github/actions/setup-terraform-env
- name: Terraform Init and Validate
env:
BW_PROJECT_ID: ${{ secrets.BW_PROJECT_ID }}
BW_ORGANIZATION_ID: ${{ secrets.BW_ORGANIZATION_ID }}
BW_ACCESS_TOKEN: ${{ secrets.BW_ACCESS_TOKEN }}
SYSTEM_ID: ${{ steps.get-host-info.outputs.system-id }}
run: |
cd terraform/iac
export TF_VAR_system_id=$SYSTEM_ID
sectool -f ../../sectool.json exec terraform init
sectool -f ../../sectool.json exec terraform validate
sectool -f ../../sectool.json exec terraform fmt -check
sectool -f ../../sectool.json exec terraform plan