|
1 |
| -name: 'Terraform GitHub Actions' |
| 1 | +name: static-checks |
| 2 | + |
2 | 3 | on:
|
3 | 4 | pull_request:
|
4 |
| - branches: |
5 |
| - - master |
6 | 5 |
|
7 | 6 | jobs:
|
8 |
| - terraform: |
9 |
| - name: 'Terraform' |
| 7 | + versionExtract: |
| 8 | + name: Get min/max versions |
10 | 9 | runs-on: ubuntu-latest
|
| 10 | + |
11 | 11 | steps:
|
12 |
| - - name: 'Checkout' |
13 |
| - uses: actions/checkout@master |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v2 |
14 | 14 |
|
15 |
| - - name: Configure AWS Credentials |
16 |
| - uses: clouddrove/configure-aws-credentials@v1 |
17 |
| - with: |
18 |
| - aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }} |
19 |
| - aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }} |
20 |
| - aws-region: us-east-2 |
| 15 | + - name: Terraform min/max versions |
| 16 | + id: minMax |
| 17 | + uses: clowdhaus/terraform-min-max@main |
| 18 | + outputs: |
| 19 | + minVersion: ${{ steps.minMax.outputs.minVersion }} |
| 20 | + maxVersion: ${{ steps.minMax.outputs.maxVersion }} |
21 | 21 |
|
22 |
| - - name: 'Terraform Format' |
23 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
24 |
| - with: |
25 |
| - actions_subcommand: 'fmt' |
26 | 22 |
|
27 |
| - - name: 'Terraform init for memcached' |
28 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
29 |
| - with: |
30 |
| - actions_subcommand: 'init' |
31 |
| - tf_actions_working_dir: ./_example/memcached |
| 23 | + versionEvaluate: |
| 24 | + name: Evaluate Terraform versions |
| 25 | + runs-on: ubuntu-latest |
| 26 | + needs: versionExtract |
| 27 | + strategy: |
| 28 | + fail-fast: false |
| 29 | + matrix: |
| 30 | + version: |
| 31 | + - ${{ needs.versionExtract.outputs.minVersion }} |
| 32 | + - ${{ needs.versionExtract.outputs.maxVersion }} |
| 33 | + directory: |
| 34 | + - _example/memcached |
| 35 | + - _example/redis |
| 36 | + - _example/redis-cluster |
32 | 37 |
|
33 |
| - - name: 'Terraform validate for memcached' |
34 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
35 |
| - with: |
36 |
| - actions_subcommand: 'validate' |
37 |
| - tf_actions_working_dir: ./_example/memcached |
| 38 | + steps: |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v2 |
38 | 41 |
|
39 |
| - - name: 'Terraform plan for memcached' |
40 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
| 42 | + - name: Install Terraform v${{ matrix.version }} |
| 43 | + uses: hashicorp/setup-terraform@v1 |
41 | 44 | with:
|
42 |
| - actions_subcommand: 'plan' |
43 |
| - tf_actions_working_dir: ./_example/memcached |
| 45 | + terraform_version: ${{ matrix.version }} |
44 | 46 |
|
45 |
| - - name: 'Terraform init for redis' |
46 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
| 47 | + - name: 'Configure AWS Credentials' |
| 48 | + uses: clouddrove/configure-aws-credentials@v1 |
47 | 49 | with:
|
48 |
| - actions_subcommand: 'init' |
49 |
| - tf_actions_working_dir: ./_example/redis |
| 50 | + aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }} |
| 51 | + aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }} |
| 52 | + aws-region: us-east-2 |
50 | 53 |
|
51 |
| - - name: 'Terraform validate for redis' |
52 |
| - uses: 'clouddrove/github-actions@v9.0' |
53 |
| - with: |
54 |
| - actions_subcommand: 'validate' |
55 |
| - tf_actions_working_dir: ./_example/redis |
| 54 | + - name: Init & validate v${{ matrix.version }} |
| 55 | + run: | |
| 56 | + cd ${{ matrix.directory }} |
| 57 | + terraform init |
| 58 | + terraform validate |
| 59 | + terraform plan -input=false -no-color |
56 | 60 |
|
57 |
| - - name: 'Terraform plan for redis' |
58 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
| 61 | + - name: tflint |
| 62 | + uses: reviewdog/action-tflint@master |
59 | 63 | with:
|
60 |
| - actions_subcommand: 'plan' |
61 |
| - tf_actions_working_dir: ./_example/redis |
| 64 | + github_token: ${{ secrets.GITHUB }} |
| 65 | + working_directory: ${{ matrix.directory }} |
| 66 | + fail_on_error: 'true' |
| 67 | + filter_mode: 'nofilter' |
| 68 | + flags: '--module' |
62 | 69 |
|
63 |
| - - name: 'Terraform init for redis-cluster' |
64 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
65 |
| - with: |
66 |
| - actions_subcommand: 'init' |
67 |
| - tf_actions_working_dir: ./_example/redis-cluster |
| 70 | + format: |
| 71 | + name: Check code format |
| 72 | + runs-on: ubuntu-latest |
| 73 | + needs: versionExtract |
68 | 74 |
|
69 |
| - - name: 'Terraform validate for redis-cluster' |
70 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
71 |
| - with: |
72 |
| - actions_subcommand: 'validate' |
73 |
| - tf_actions_working_dir: ./_example/redis-cluster |
| 75 | + steps: |
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v2 |
74 | 78 |
|
75 |
| - - name: 'Terraform plan for redis-cluster' |
76 |
| - uses: 'clouddrove/github-actions@v9.0.1' |
| 79 | + - name: Install Terraform v${{ needs.versionExtract.outputs.maxVersion }} |
| 80 | + uses: hashicorp/setup-terraform@v1 |
77 | 81 | with:
|
78 |
| - actions_subcommand: 'plan' |
79 |
| - tf_actions_working_dir: ./_example/redis-cluster |
| 82 | + terraform_version: ${{ needs.versionExtract.outputs.maxVersion }} |
80 | 83 |
|
81 |
| - |
82 |
| - - name: 'Slack Notification' |
83 |
| - uses: clouddrove/action-slack@v2 |
84 |
| - with: |
85 |
| - status: ${{ job.status }} |
86 |
| - fields: repo,author |
87 |
| - author_name: 'CloudDrove' |
88 |
| - env: |
89 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required |
90 |
| - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required |
91 |
| - if: always() |
| 84 | + - name: Check Terraform format changes |
| 85 | + run: terraform fmt --recursive |
0 commit comments