Skip to content

chore: GH Action to validate samples.tfvars with variables.tf #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/dc_tfvars_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: DC Mission - tfvars check

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
paths:
- 'released/discovery_center/**'


jobs:
terraform-console-validate:
name: Validate Consistency of tfvar files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false

- name: Get changed directories
id: changed-dirs
uses: tj-actions/changed-files@v44
with:
dir_names: 'true'

- name: Validate Terraform tfvars
if: steps.changed-dirs.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-dirs.outputs.all_changed_files }}
shell: bash
run: |
EXIT_CODE=0
for dir in ${ALL_CHANGED_FILES}; do
if [[ $dir == *"step"* ]]; then
echo "Validating Terraform tfvars files in $dir"
cd $dir
terraform init -backend=false || EXIT_CODE=$?
echo '"test"' | terraform console -var-file sample.tfvars > validatetfvars.txt
if [[ $(<validatetfvars.txt) != '"test"' ]]; then
echo "sample.tfvars does not match variables.tf";
EXIT_CODE=1;
else
echo "sample.tfvars matches variables.tf";
fi
rm -rf ".terraform/"
rm -rf validatetfvars.txt
fi
cd ${{ github.workspace }}
done
exit $EXIT_CODE