-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (63 loc) · 3.19 KB
/
check-infra-deploy-status.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# This workflow checks the status of infrastructure deployments to see whether
# infrastructure code configuration matches the actual state of the infrastructure.
# It does this by checking that Terraform plans show an empty diff (no changes)
# across all root modules and backend configurations.
name: Check infra deploy status
on:
workflow_dispatch:
schedule:
# Run every day at 07:00 UTC (3am ET, 12am PT) after engineers are likely done with work
- cron: "0 7 * * *"
jobs:
collect-configs:
name: Collect configs
runs-on: ubuntu-latest
outputs:
root_module_configs: ${{ steps.collect-infra-deploy-status-check-configs.outputs.root_module_configs }}
steps:
- uses: actions/checkout@v4
- name: Collect root module configurations
id: collect-infra-deploy-status-check-configs
run: |
root_module_configs="$(./bin/infra-deploy-status-check-configs)"
echo "${root_module_configs}"
echo "root_module_configs=${root_module_configs}" >> "$GITHUB_OUTPUT"
check:
name: ${{ matrix.root_module_subdir }} ${{ matrix.backend_config_name }}
runs-on: ubuntu-latest
needs: collect-configs
# Skip this job if there are no root module configurations to check,
# otherwise the GitHub actions will give the error: "Matrix must define at least one vector"
if: ${{ needs.collect-configs.outputs.root_module_configs != '[]' }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.collect-configs.outputs.root_module_configs) }}
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.8.3
terraform_wrapper: false
- name: Configure AWS credentials
uses: ./.github/actions/configure-aws-credentials
with:
account_name: ${{ matrix.infra_layer == 'accounts' && matrix.account_name || null }}
network_name: ${{ matrix.infra_layer == 'networks' && matrix.backend_config_name || null }}
app_name: ${{ contains(fromJSON('["build-repository", "database", "service"]'), matrix.infra_layer) && matrix.app_name || null }}
environment: ${{ contains(fromJSON('["build-repository", "database", "service"]'), matrix.infra_layer) && matrix.backend_config_name || null }}
- name: Check Terraform plan
run: |
echo "::group::Initialize Terraform"
echo terraform -chdir="infra/${{ matrix.root_module_subdir }}" init -input=false -reconfigure -backend-config="${{ matrix.backend_config_name }}.s3.tfbackend"
terraform -chdir="infra/${{ matrix.root_module_subdir }}" init -input=false -reconfigure -backend-config="${{ matrix.backend_config_name }}.s3.tfbackend"
echo "::endgroup::"
echo "::group::Check Terraform plan"
echo terraform -chdir="infra/${{ matrix.root_module_subdir }}" plan -input=false -detailed-exitcode ${{ matrix.extra_params }}
terraform -chdir="infra/${{ matrix.root_module_subdir }}" plan -input=false -detailed-exitcode ${{ matrix.extra_params }}
echo "::endgroup::"
env:
TF_IN_AUTOMATION: "true"