update validation workflow #2
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 | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
terraform-validate: | |
name: Validate Terraform | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Find Terraform directories | |
id: find-terraform-dirs | |
run: | | |
dirs=$(find . -type f -name "main.tf" -exec dirname {} \; | sort | uniq) | |
echo "::set-output name=dirs::${dirs}" | |
- name: Find and validate all Terraform configurations | |
shell: bash | |
run: | | |
# Find all directories containing *.tf files | |
find . -type f -name "*.tf" -print0 | xargs -0 -n1 dirname | sort -u | while IFS= read -r dir; do | |
echo "Validating Terraform configuration in '${dir}'" | |
cd "${dir}" || exit | |
# Initialize Terraform without backend to prevent remote state issues | |
terraform init -backend=false | |
# Validate the configuration | |
terraform validate | |
# Return to the root directory | |
cd - > /dev/null | |
done |