44 pull_request :
55
66jobs :
7+ configs :
8+ runs-on : ubuntu-latest
9+ steps :
10+ - name : Checkout source code
11+ uses : actions/checkout@v4
12+ - name : Find all configs
13+ id : find
14+ uses : bendrucker/find-terraform-modules@v1
15+ with :
16+ working-directory : tofu/config
17+ - name : Show all matching configs
18+ shell : bash
19+ run : |
20+ mods=(${{ join(fromJSON(steps.find.outputs.modules), ' ') }})
21+ printf "%s\n" "${mods[@]}"
22+ - name : Find all changed files
23+ id : diff
24+ uses : technote-space/get-diff-action@v6
25+ with :
26+ FORMAT : json
27+ - name : Show changed files
28+ run : |
29+ echo "${{ steps.diff.outputs.diff }}"
30+ - name : Get the modified configs
31+ id : modified
32+ uses : actions/github-script@v7
33+ with :
34+ script : |
35+ const configs = ${{ steps.find.outputs.modules }}
36+ const diff = ${{ steps.diff.outputs.diff }}
37+ const modifiedConfigs = configs.filter(
38+ (config) => {
39+ return !!diff.find(file => new RegExp(`^${config}/.+`).test(file))
40+ }
41+ ).map(config => config.replace(/^tofu\/config\//, ''))
42+
43+ core.setOutput('configs', modifiedConfigs)
44+ - name : Show modified configs
45+ run : |
46+ echo "${{ steps.modified.outputs.configs }}"
47+ outputs :
48+ configs : ${{ steps.modified.outputs.configs }}
49+
750 plan :
851 uses : ./.github/workflows/plan.yaml
52+ needs : configs
953 permissions :
1054 contents : read
1155 id-token : write
56+ strategy :
57+ matrix :
58+ config : ${{ fromJson(needs.configs.outputs.configs) }}
1259 with :
1360 environment : development
61+ config : ${{ matrix.config }}
1462 secrets :
1563 AWS_REGION : ${{ secrets.AWS_REGION }}
1664 AWS_ROLE_ARN : ${{ secrets.AWS_ROLE_ARN }}
@@ -23,17 +71,20 @@ jobs:
2371
2472 comment :
2573 runs-on : ubuntu-latest
26- needs : plan
74+ needs :
75+ - configs
76+ - plan
2777 permissions :
2878 contents : read
2979 pull-requests : write
30- env :
31- CONFIG_PATH : ./tofu/config/development
80+ strategy :
81+ matrix :
82+ config : ${{ fromJson(needs.configs.outputs.configs) }}
3283 steps :
3384 - name : Download plan file
3485 uses : actions/download-artifact@v4
3586 with :
36- name : tfplan
87+ name : ${{ matrix.config }}- tfplan
3788 - uses : actions/github-script@v7
3889 with :
3990 github-token : ${{ secrets.GITHUB_TOKEN }}
@@ -45,15 +96,15 @@ jobs:
4596 issue_number: context.issue.number,
4697 })
4798 const botComment = comments.find(comment => {
48- return comment.user.type === 'Bot' && comment.body.includes('## Plan output')
99+ return comment.user.type === 'Bot' && comment.body.includes('## Plan output for ${{ matrix.config }} config ')
49100 })
50101
51102 // Read the contents of the plan.
52103 const fs = require('fs');
53104 const plan = fs.readFileSync('./plan.txt', 'utf8');
54105
55106 // Prepare the format of the comment.
56- const output = `## Plan output\n\n\`\`\`\n${plan}\n\`\`\``
107+ const output = `## Plan output for ${{ matrix.config }} config \n\n\`\`\`\n${plan}\n\`\`\``
57108
58109 // If we have a comment, update it. Otherwise, create a new one.
59110 if (botComment) {
0 commit comments