2022-09-20 07:38:22 -04:00
|
|
|
name: Terraform validation
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2022-10-18 10:17:41 -04:00
|
|
|
- "release/**"
|
2022-09-20 07:38:22 -04:00
|
|
|
paths:
|
|
|
|
- "**.tf"
|
2022-11-29 12:05:50 -05:00
|
|
|
- "**.lock.hcl"
|
2023-02-14 14:01:00 -05:00
|
|
|
- ".github/workflows/test-tf.yml"
|
2022-09-20 07:38:22 -04:00
|
|
|
pull_request:
|
|
|
|
paths:
|
|
|
|
- "**.tf"
|
2022-11-29 12:05:50 -05:00
|
|
|
- "**.lock.hcl"
|
2023-02-14 14:01:00 -05:00
|
|
|
- ".github/workflows/test-tf.yml"
|
2022-09-20 07:38:22 -04:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
tfsec:
|
|
|
|
name: terraform
|
2022-11-10 10:55:24 -05:00
|
|
|
runs-on: ubuntu-22.04
|
2022-09-20 07:38:22 -04:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2023-01-05 10:17:51 -05:00
|
|
|
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
2022-09-20 07:38:22 -04:00
|
|
|
with:
|
2022-12-19 09:21:28 -05:00
|
|
|
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
2023-02-20 09:31:58 -05:00
|
|
|
# No token available for forks, so we can't push changes
|
|
|
|
token: ${{ !github.event.pull_request.head.repo.fork && secrets.TIDY_RENOVATE_PUSH || '' }}
|
2022-09-20 07:38:22 -04:00
|
|
|
|
|
|
|
- name: Setup Terraform
|
2022-11-02 06:00:40 -04:00
|
|
|
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # tag=v2.0.3
|
2022-09-20 07:38:22 -04:00
|
|
|
|
|
|
|
- name: Terraform format and validate
|
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
dirs=$(find . -type f -name "*.tf" -exec dirname "{}" \; | sort -ud)
|
|
|
|
result=0
|
|
|
|
for dir in $dirs; do
|
|
|
|
echo "Checking $dir"
|
2022-11-11 08:49:16 -05:00
|
|
|
terraform -chdir="$dir" init || result=1
|
|
|
|
terraform -chdir="$dir" fmt -check=true -diff=true || result=1
|
|
|
|
terraform -chdir="$dir" validate -no-color || result=1
|
2022-09-20 07:38:22 -04:00
|
|
|
done
|
|
|
|
exit $result
|
2022-11-29 12:05:50 -05:00
|
|
|
|
|
|
|
- name: Check HCL lock files are up to date
|
2022-11-29 12:18:20 -05:00
|
|
|
id: hcl-lock
|
2022-11-29 12:05:50 -05:00
|
|
|
shell: bash
|
|
|
|
run: |
|
|
|
|
dirs=$( find . -type f -name "*.lock.hcl" -exec dirname "{}" \; | sort -ud)
|
|
|
|
for dir in $dirs; do
|
|
|
|
echo "Checking $dir"
|
|
|
|
terraform -chdir="$dir" init
|
|
|
|
terraform -chdir="$dir" providers lock -platform=linux_arm64 -platform=linux_amd64 -platform=darwin_arm64 -platform=darwin_amd64 -platform=windows_amd64
|
|
|
|
done
|
|
|
|
git diff --exit-code
|
2022-11-29 12:18:20 -05:00
|
|
|
|
|
|
|
- name: Push changes on renovate
|
2023-01-17 12:49:00 -05:00
|
|
|
if: failure() && (steps.hcl-lock.conclusion == 'failure') && startsWith(github.head_ref, 'renovate/')
|
2022-11-29 12:18:20 -05:00
|
|
|
shell: bash
|
|
|
|
run: |
|
2023-02-20 09:33:59 -05:00
|
|
|
git config --global user.name "edgelessci"
|
|
|
|
git config --global user.email "edgelessci@users.noreply.github.com"
|
2023-01-12 12:13:25 -05:00
|
|
|
git commit -am "deps: update HCL lock files"
|
2022-11-29 12:18:20 -05:00
|
|
|
git push
|