|
| 1 | +name: Terraform Pre-Commit |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + terraform-docs-version: |
| 7 | + type: string |
| 8 | + required: false |
| 9 | + default: v0.16.0 |
| 10 | + tflint-version: |
| 11 | + type: string |
| 12 | + required: false |
| 13 | + default: v0.48.0 |
| 14 | + |
| 15 | +jobs: |
| 16 | + collectInputs: |
| 17 | + name: Collect workflow inputs |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + directories: ${{ steps.dirs.outputs.directories }} |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Get root directories |
| 26 | + id: dirs |
| 27 | + uses: clowdhaus/terraform-composite-actions/[email protected] |
| 28 | + |
| 29 | + preCommitMinVersions: |
| 30 | + name: Min TF pre-commit |
| 31 | + needs: collectInputs |
| 32 | + runs-on: ubuntu-latest |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + directory: ${{ fromJson(needs.collectInputs.outputs.directories) }} |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Terraform min/max versions |
| 41 | + id: minMax |
| 42 | + |
| 43 | + with: |
| 44 | + directory: ${{ matrix.directory }} |
| 45 | + |
| 46 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 47 | + # Run only validate pre-commit check on min version supported |
| 48 | + if: ${{ matrix.directory != '.' }} |
| 49 | + uses: clowdhaus/terraform-composite-actions/[email protected] |
| 50 | + with: |
| 51 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 52 | + args: 'terraform-validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*' |
| 53 | + |
| 54 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} |
| 55 | + # Run only validate pre-commit check on min version supported |
| 56 | + if: ${{ matrix.directory == '.' }} |
| 57 | + uses: clowdhaus/terraform-composite-actions/[email protected] |
| 58 | + with: |
| 59 | + terraform-version: ${{ steps.minMax.outputs.minVersion }} |
| 60 | + args: 'terraform-validate --color=always --show-diff-on-failure --files $(ls *.tf)' |
| 61 | + |
| 62 | + preCommitMaxVersion: |
| 63 | + name: Max TF pre-commit |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: collectInputs |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v4 |
| 69 | + with: |
| 70 | + ref: ${{ github.event.pull_request.head.ref }} |
| 71 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 72 | + |
| 73 | + - name: Terraform min/max versions |
| 74 | + id: minMax |
| 75 | + |
| 76 | + |
| 77 | + # Step required as tflint pre-commit hook requires module to be initialised |
| 78 | + - run: terraform init |
| 79 | + |
| 80 | + - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} |
| 81 | + uses: clowdhaus/terraform-composite-actions/[email protected] |
| 82 | + with: |
| 83 | + terraform-version: ${{ steps.minMax.outputs.maxVersion }} |
| 84 | + terraform-docs-version: ${{ inputs.terraform-docs-version }} |
| 85 | + tflint-version: ${{ inputs.tflint-version }} |
0 commit comments