|
| 1 | +name: Validate and Test Terraform manifests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +env: |
| 7 | + TERRAFORM_VERSION: ~1.9 |
| 8 | + |
| 9 | +jobs: |
| 10 | + terraform: |
| 11 | + name: terraform |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Terraform |
| 18 | + uses: hashicorp/setup-terraform@v3 |
| 19 | + with: |
| 20 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 21 | + |
| 22 | + - name: Ensure Terraform code is formated |
| 23 | + run: terraform fmt -check |
| 24 | + |
| 25 | + - name: Terraform Init |
| 26 | + run: terraform init |
| 27 | + |
| 28 | + - name: Validate Terraform code |
| 29 | + run: terraform validate -no-color |
| 30 | + |
| 31 | + trivy: |
| 32 | + name: trivy |
| 33 | + runs-on: ubuntu-latest |
| 34 | + needs: terraform |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup Terraform |
| 40 | + uses: hashicorp/setup-terraform@v3 |
| 41 | + with: |
| 42 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 43 | + |
| 44 | + - name: Terraform Init |
| 45 | + run: terraform init |
| 46 | + |
| 47 | + - name: Run trivy with reviewdog output on the PR |
| 48 | + uses: reviewdog/action-trivy@v1 |
| 49 | + with: |
| 50 | + trivy_command: config |
| 51 | + trivy_target: . |
| 52 | + github_token: ${{ secrets.github_token }} |
| 53 | + reporter: github-pr-review |
| 54 | + filter_mode: diff_context |
| 55 | + fail_on_error: "true" |
| 56 | + |
| 57 | + tflint: |
| 58 | + name: tflint |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: terraform |
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@v4 |
| 64 | + |
| 65 | + - name: Setup Terraform |
| 66 | + uses: hashicorp/setup-terraform@v3 |
| 67 | + with: |
| 68 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 69 | + |
| 70 | + - name: Terraform Init |
| 71 | + run: terraform init |
| 72 | + |
| 73 | + - name: Check with tflint |
| 74 | + uses: reviewdog/action-tflint@v1 |
| 75 | + with: |
| 76 | + github_token: ${{ secrets.github_token }} |
| 77 | + reporter: github-pr-review |
| 78 | + fail_on_error: "true" |
| 79 | + filter_mode: diff_context |
| 80 | + flags: "--module" |
| 81 | + |
| 82 | + terratest: |
| 83 | + name: terratest |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: |
| 86 | + - terraform |
| 87 | + - trivy |
| 88 | + - tflint |
| 89 | + steps: |
| 90 | + - name: Checkout |
| 91 | + uses: actions/checkout@v4 |
| 92 | + |
| 93 | + - name: Setup Terraform |
| 94 | + uses: hashicorp/setup-terraform@v3 |
| 95 | + with: |
| 96 | + terraform_version: ${{ env.TERRAFORM_VERSION }} |
| 97 | + |
| 98 | + - name: Setup go |
| 99 | + uses: actions/setup-go@v5 |
| 100 | + with: |
| 101 | + go-version-file: tests/go.mod |
| 102 | + cache-dependency-path: | |
| 103 | + tests/go.sum |
| 104 | +
|
| 105 | + - name: Run terratest |
| 106 | + run: make terratest |
0 commit comments