|
3 | 3 | push:
|
4 | 4 | branches:
|
5 | 5 | - main
|
| 6 | + - npalm/* |
6 | 7 | pull_request:
|
7 |
| - paths: ["**/*.tf", "**/*.hcl", ".github/workflows/terraform.yml"] |
| 8 | + paths: ["**/*.tf", "**/*.hcl", ".github/workflows/terraform.yml", ".utils/**"] |
| 9 | + paths-ignore: ["lambdas/**"] |
8 | 10 |
|
9 | 11 | permissions:
|
10 | 12 | contents: read
|
11 | 13 | pull-requests: write
|
12 | 14 |
|
13 |
| -env: |
14 |
| - AWS_REGION: eu-west-1 |
15 | 15 | jobs:
|
16 |
| - verify_module: |
17 |
| - name: Verify module |
18 |
| - strategy: |
19 |
| - matrix: |
20 |
| - terraform: [1.5.6, "latest"] |
| 16 | + dirs: |
| 17 | + name: Find modules |
21 | 18 | runs-on: ubuntu-latest
|
22 |
| - container: |
23 |
| - image: hashicorp/terraform:${{ matrix.terraform }} |
24 |
| - steps: |
25 |
| - - name: "Checkout" |
26 |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
27 |
| - - name: "Fake zip files" # Validate will fail if it cannot find the zip files |
28 |
| - run: | |
29 |
| - touch lambdas/functions/webhook/webhook.zip |
30 |
| - touch lambdas/functions/control-plane/runners.zip |
31 |
| - touch lambdas/functions/gh-agent-syncer/runner-binaries-syncer.zip |
32 |
| - touch lambdas/functions/ami-housekeeper/ami-housekeeper.zip |
33 |
| - touch lambdas/functions/termination-watcher/termination-watcher.zip |
34 |
| - - name: terraform init |
35 |
| - run: terraform init -get -backend=false -input=false |
36 |
| - - if: contains(matrix.terraform, '1.5.') |
37 |
| - name: check terraform formatting |
38 |
| - run: terraform fmt -recursive -check=true -write=false |
39 |
| - - if: contains(matrix.terraform, 'latest') # check formatting for the latest release but avoid failing the build |
40 |
| - name: check terraform formatting |
41 |
| - run: terraform fmt -recursive -check=true -write=false |
42 |
| - continue-on-error: true |
43 |
| - - name: validate terraform |
44 |
| - run: terraform validate |
45 |
| - - if: contains(matrix.terraform, '1.5.') |
46 |
| - name: Fix for actions/cache on alpine |
47 |
| - run: apk add --no-cache tar |
48 |
| - continue-on-error: true |
49 |
| - - if: contains(matrix.terraform, '1.5.') |
50 |
| - uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1 |
51 |
| - name: Cache TFLint plugin dir |
52 |
| - with: |
53 |
| - path: ~/.tflint.d/plugins |
54 |
| - key: tflint-${{ hashFiles('.tflint.hcl') }} |
55 |
| - - if: contains(matrix.terraform, '1.5.') |
56 |
| - name: Setup TFLint |
57 |
| - uses: terraform-linters/setup-tflint@19a52fbac37dacb22a09518e4ef6ee234f2d4987 # v4.0.0 |
58 |
| - with: |
59 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
60 |
| - - if: contains(matrix.terraform, '1.5.') |
61 |
| - name: Run TFLint |
62 |
| - run: | |
63 |
| - tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl |
64 |
| - tflint -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars |
65 |
| -
|
66 |
| - verify_modules: |
67 |
| - name: Verify modules |
68 |
| - strategy: |
69 |
| - fail-fast: false |
70 |
| - matrix: |
71 |
| - terraform: [1.5.6, "latest"] |
72 |
| - module: |
73 |
| - [ |
74 |
| - "ami-housekeeper", |
75 |
| - "download-lambda", |
76 |
| - "lambda", |
77 |
| - "multi-runner", |
78 |
| - "runner-binaries-syncer", |
79 |
| - "runners", |
80 |
| - "setup-iam-permissions", |
81 |
| - "ssm", |
82 |
| - "termination-watcher", |
83 |
| - "webhook", |
84 |
| - ] |
85 |
| - defaults: |
86 |
| - run: |
87 |
| - working-directory: modules/${{ matrix.module }} |
88 |
| - runs-on: ubuntu-latest |
89 |
| - container: |
90 |
| - image: hashicorp/terraform:${{ matrix.terraform }} |
91 | 19 | steps:
|
92 | 20 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
93 |
| - - name: terraform init |
94 |
| - run: terraform init -get -backend=false -input=false |
95 |
| - - if: contains(matrix.terraform, '1.3.') |
96 |
| - name: check terraform formatting |
97 |
| - run: terraform fmt -recursive -check=true -write=false |
98 |
| - - if: contains(matrix.terraform, 'latest') # check formatting for the latest release but avoid failing the build |
99 |
| - name: check terraform formatting |
100 |
| - run: terraform fmt -recursive -check=true -write=false |
101 |
| - continue-on-error: true |
102 |
| - - name: validate terraform |
103 |
| - run: terraform validate |
104 |
| - - if: contains(matrix.terraform, '1.3.') |
105 |
| - name: Fix for actions/cache on alpine |
106 |
| - run: apk add --no-cache tar |
107 |
| - continue-on-error: true |
108 |
| - - if: contains(matrix.terraform, '1.3.') |
109 |
| - uses: actions/cache@v4 |
110 |
| - name: Cache TFLint plugin dir |
111 |
| - with: |
112 |
| - path: ~/.tflint.d/plugins |
113 |
| - key: tflint-${{ hashFiles('.tflint.hcl') }} |
114 |
| - - if: contains(matrix.terraform, '1.3.') |
115 |
| - name: Setup TFLint |
116 |
| - uses: terraform-linters/setup-tflint@v4 |
117 |
| - with: |
118 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
119 |
| - - if: contains(matrix.terraform, '1.3.') |
120 |
| - name: Run TFLint |
121 |
| - working-directory: ${{ github.workspace }} |
| 21 | + |
| 22 | + - id: find |
| 23 | + # Ignore directories whose names start with .terraform or obsolete |
| 24 | + shell: bash |
122 | 25 | run: |
|
123 |
| - tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl --chdir modules/${{ matrix.module }} |
124 |
| - tflint -f compact -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars --chdir modules/${{ matrix.module }} |
| 26 | + source ./.utils/find.sh |
| 27 | + #modules=$(findAllTerraformDirs --ignores "examples") |
| 28 | + #modules=$(echo $modules | jq 'map(select(. | contains("./modules/multi-runner")))') |
| 29 | + #examples=$(findAllTerraformDirs --ignores "modules" --hide-root) |
| 30 | + modules=$(findAllTerraformDirs) |
| 31 | + echo "modules=$(echo $modules)" >> $GITHUB_OUTPUT |
| 32 | + echo "examples=$(echo $examples)" >> $GITHUB_OUTPUT |
| 33 | + outputs: |
| 34 | + tf_modules: ${{ steps.find.outputs.modules }} |
| 35 | + tf_examples: ${{ steps.find.outputs.examples }} |
125 | 36 |
|
126 |
| - verify_examples: |
127 |
| - name: Verify examples |
| 37 | + verify_all: |
| 38 | + uses: ./.github/workflows/terraform-validate-template.yml |
| 39 | + name: Verify module ${{ matrix.module }} |
| 40 | + needs: dirs |
| 41 | + with: |
| 42 | + terraform_version: ${{ matrix.terraform }} |
| 43 | + module: ${{ matrix.module }} |
128 | 44 | strategy:
|
129 | 45 | fail-fast: false
|
130 | 46 | matrix:
|
131 |
| - terraform: [1.5.6, "latest"] |
132 |
| - example: |
133 |
| - [ |
134 |
| - "default", |
135 |
| - "ubuntu", |
136 |
| - "prebuilt", |
137 |
| - "arm64", |
138 |
| - "ephemeral", |
139 |
| - "termination-watcher", |
140 |
| - "windows", |
141 |
| - "multi-runner", |
142 |
| - ] |
143 |
| - defaults: |
144 |
| - run: |
145 |
| - working-directory: examples/${{ matrix.example }} |
146 |
| - runs-on: ubuntu-latest |
147 |
| - container: |
148 |
| - image: hashicorp/terraform:${{ matrix.terraform }} |
149 |
| - steps: |
150 |
| - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
151 |
| - - name: terraform init |
152 |
| - run: terraform init -get -backend=false -input=false |
153 |
| - - if: contains(matrix.terraform, '1.5.') |
154 |
| - name: check terraform formatting |
155 |
| - run: terraform fmt -recursive -check=true -write=false |
156 |
| - - if: contains(matrix.terraform, 'latest') # check formatting for the latest release but avoid failing the build |
157 |
| - name: check terraform formatting |
158 |
| - run: terraform fmt -recursive -check=true -write=false |
159 |
| - continue-on-error: true |
160 |
| - - name: validate terraform |
161 |
| - run: terraform validate |
162 |
| - - if: contains(matrix.terraform, '1.5.') |
163 |
| - name: Fix for actions/cache on alpine |
164 |
| - run: apk add --no-cache tar |
165 |
| - continue-on-error: true |
166 |
| - - if: contains(matrix.terraform, '1.5.') |
167 |
| - uses: actions/cache@v4 |
168 |
| - name: Cache TFLint plugin dir |
169 |
| - with: |
170 |
| - path: ~/.tflint.d/plugins |
171 |
| - key: tflint-${{ hashFiles('.tflint.hcl') }} |
172 |
| - - if: contains(matrix.terraform, '1.5.') |
173 |
| - name: Setup TFLint |
174 |
| - uses: terraform-linters/setup-tflint@v4 |
175 |
| - with: |
176 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
177 |
| - - if: contains(matrix.terraform, '1.5.') |
178 |
| - name: Run TFLint |
179 |
| - working-directory: ${{ github.workspace }} |
180 |
| - run: | |
181 |
| - tflint --init -c ${GITHUB_WORKSPACE}/.tflint.hcl --chdir modules/${{ matrix.module }} |
182 |
| - tflint -f compact -c ${GITHUB_WORKSPACE}/.tflint.hcl --var-file ${GITHUB_WORKSPACE}/.github/lint/tflint.tfvars --chdir examples/${{ matrix.example }} |
| 47 | + terraform: ["1.5", "latest"] |
| 48 | + module: ${{ fromJson(needs.dirs.outputs.tf_modules) }} |
0 commit comments