| 
 | 1 | +name: Terraform Checks  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  workflow_call:  | 
 | 5 | + | 
 | 6 | +env:  | 
 | 7 | +  TERRAFORM_DOCS_VERSION: v0.18.0  | 
 | 8 | +  TFLINT_VERSION: v0.52.0  | 
 | 9 | + | 
 | 10 | +jobs:  | 
 | 11 | +  test:  | 
 | 12 | +    name: Test  | 
 | 13 | +    runs-on: ubuntu-latest  | 
 | 14 | +    steps:  | 
 | 15 | +      - name: Setup Terraform  | 
 | 16 | +        uses: hashicorp/setup-terraform@v3  | 
 | 17 | +        with:  | 
 | 18 | +          terraform_version: "1.8.4"  | 
 | 19 | + | 
 | 20 | +      - name: Initialize Terraform  | 
 | 21 | +        id: init  | 
 | 22 | +        run: terraform init -input=false  | 
 | 23 | + | 
 | 24 | +      - name: Terraform Test  | 
 | 25 | +        id: fmt  | 
 | 26 | +        run: terraform test  | 
 | 27 | + | 
 | 28 | +  collectInputs:  | 
 | 29 | +    name: Collect workflow inputs  | 
 | 30 | +    needs: test  | 
 | 31 | +    runs-on: ubuntu-latest  | 
 | 32 | +    outputs:  | 
 | 33 | +      directories: ${{ steps.dirs.outputs.directories }}  | 
 | 34 | +    steps:  | 
 | 35 | +      - name: Checkout  | 
 | 36 | +        uses: actions/checkout@v4  | 
 | 37 | + | 
 | 38 | +      - name: Get root directories  | 
 | 39 | +        id: dirs  | 
 | 40 | +        uses:  clowdhaus/terraform-composite-actions/[email protected]  | 
 | 41 | + | 
 | 42 | +  preCommitMinVersions:  | 
 | 43 | +    name: Min TF pre-commit  | 
 | 44 | +    needs: collectInputs  | 
 | 45 | +    runs-on: ubuntu-latest  | 
 | 46 | +    strategy:  | 
 | 47 | +      matrix:  | 
 | 48 | +        directory: ${{ fromJson(needs.collectInputs.outputs.directories) }}  | 
 | 49 | +    steps:  | 
 | 50 | +      # https://github.com/orgs/community/discussions/25678#discussioncomment-5242449  | 
 | 51 | +      - name: Delete huge unnecessary tools folder  | 
 | 52 | +        run: |  | 
 | 53 | +          rm -rf /opt/hostedtoolcache/CodeQL  | 
 | 54 | +          rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk  | 
 | 55 | +          rm -rf /opt/hostedtoolcache/Ruby  | 
 | 56 | +          rm -rf /opt/hostedtoolcache/go  | 
 | 57 | +
  | 
 | 58 | +      - name: Checkout  | 
 | 59 | +        uses: actions/checkout@v4  | 
 | 60 | + | 
 | 61 | +      - name: Terraform min/max versions  | 
 | 62 | +        id: minMax  | 
 | 63 | + | 
 | 64 | +        with:  | 
 | 65 | +          directory: ${{ matrix.directory }}  | 
 | 66 | + | 
 | 67 | +      - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}  | 
 | 68 | +        # Run only validate pre-commit check on min version supported  | 
 | 69 | +        if: ${{ matrix.directory !=  '.' }}  | 
 | 70 | +        uses:  clowdhaus/terraform-composite-actions/[email protected]  | 
 | 71 | +        with:  | 
 | 72 | +          terraform-version: ${{ steps.minMax.outputs.minVersion }}  | 
 | 73 | +          tflint-version: ${{ env.TFLINT_VERSION }}  | 
 | 74 | +          args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*'  | 
 | 75 | + | 
 | 76 | +      - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }}  | 
 | 77 | +        # Run only validate pre-commit check on min version supported  | 
 | 78 | +        if: ${{ matrix.directory ==  '.' }}  | 
 | 79 | +        uses:  clowdhaus/terraform-composite-actions/[email protected]  | 
 | 80 | +        with:  | 
 | 81 | +          terraform-version: ${{ steps.minMax.outputs.minVersion }}  | 
 | 82 | +          tflint-version: ${{ env.TFLINT_VERSION }}  | 
 | 83 | +          args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)'  | 
 | 84 | + | 
 | 85 | +  preCommitMaxVersion:  | 
 | 86 | +    name: Max TF pre-commit  | 
 | 87 | +    runs-on: ubuntu-latest  | 
 | 88 | +    needs: collectInputs  | 
 | 89 | +    steps:  | 
 | 90 | +      # https://github.com/orgs/community/discussions/25678#discussioncomment-5242449  | 
 | 91 | +      - name: Delete huge unnecessary tools folder  | 
 | 92 | +        run: |  | 
 | 93 | +          rm -rf /opt/hostedtoolcache/CodeQL  | 
 | 94 | +          rm -rf /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk  | 
 | 95 | +          rm -rf /opt/hostedtoolcache/Ruby  | 
 | 96 | +          rm -rf /opt/hostedtoolcache/go  | 
 | 97 | +
  | 
 | 98 | +      - name: Checkout  | 
 | 99 | +        uses: actions/checkout@v4  | 
 | 100 | +        with:  | 
 | 101 | +          ref: ${{ github.event.pull_request.head.ref }}  | 
 | 102 | +          repository: ${{github.event.pull_request.head.repo.full_name}}  | 
 | 103 | + | 
 | 104 | +      - name: Terraform min/max versions  | 
 | 105 | +        id: minMax  | 
 | 106 | + | 
 | 107 | + | 
 | 108 | +      - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }}  | 
 | 109 | +        uses:  clowdhaus/terraform-composite-actions/[email protected]  | 
 | 110 | +        with:  | 
 | 111 | +          terraform-version: ${{ steps.minMax.outputs.maxVersion }}  | 
 | 112 | +          tflint-version: ${{ env.TFLINT_VERSION }}  | 
 | 113 | +          terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }}  | 
 | 114 | +          install-hcledit: true  | 
0 commit comments