Skip to content

test pre-commit

test pre-commit #81

Workflow file for this run

name: tflint
on:
pull_request:
paths:
- 'terraform/**'
- .github/workflows/tflint.yml
- .tflint.hcl
- '!**/README.md'
push:
paths:
- 'terraform/**'
- .github/workflows/tflint.yml
- .tflint.hcl
- '!**/README.md'
workflow_dispatch:
env:
terraform_version: 1.5.3
tflint_version: v0.47.0
jobs:
pre-commit:
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Cache plugin dir
uses: actions/cache@v3
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
with:
tflint_version: ${{ env.tflint_version }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Run pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --from-ref origin/master --to-ref HEAD
tflint:
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Cache plugin dir
uses: actions/cache@v3
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- name: Setup TFLint
uses: terraform-linters/[email protected]
with:
tflint_version: v0.47.0
- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Check Terraform formatting
working-directory: terraform
run: terraform fmt -recursive -check=true -write=false
- name: Init TFLint
run: tflint --init
env:
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
GITHUB_TOKEN: ${{ github.token }}
- name: Run TFLint
shell: bash
run: |
top_dir="$(pwd)"
for d in $(find ./terraform -type d -print | sed -E 's|^./||' | grep -v "^terraform$" | sort); do
echo "Checking directory ${d}"
# Skip directory if no Terraform files found
ls ${d}/*.tf >/dev/null 2>&1 || { echo "No Terraform files found, skipping..."; continue; }
echo "Run Terraform init"
terraform -chdir="${d}" init -upgrade -backend=false
echo "Validate Terraform config"
terraform validate
echo "Run tflint"
tflint --chdir="${d}" --color --config="${top_dir}/.tflint.hcl"
done
- name: Check Terraform formatting
run: terraform -chdir=terraform fmt -recursive -check=true -write=false