-
Notifications
You must be signed in to change notification settings - Fork 4
115 lines (91 loc) · 3.84 KB
/
apply_plan_clusters.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Runs terraform apply/plan for each cluster in ./terraform/clusters
name: Apply/Plan clusters
on:
push:
branches:
- master
paths:
- 'terraform/clusters/**'
pull_request:
types: [labeled, opened, synchronize, reopened]
paths:
- 'terraform/clusters/**'
jobs:
get_subscriptions:
if: contains(github.event.pull_request.labels.*.name, 'deploy') || github.event_name == 'push'
name: Get subscriptions
runs-on: ubuntu-latest
outputs:
subscriptions: ${{ steps.set-matrix.outputs.subscriptions }}
env:
path: terraform/clusters
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "subscriptions=$(ls ${{ env.path }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
get_radix_environments:
needs: get_subscriptions
if: contains(github.event.pull_request.labels.*.name, 'deploy') || github.event_name == 'push'
name: Get radix environments
runs-on: ubuntu-latest
strategy:
matrix:
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
outputs:
radix_environment: ${{ steps.set-matrix.outputs.radix_environment }}
env:
path: terraform/clusters/${{ matrix.subscriptions }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: echo "radix_environment=$(ls ${{ env.path }} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
get_clusters:
needs: [get_radix_environments, get_subscriptions]
name: Get clusters
runs-on: ubuntu-latest
strategy:
matrix:
radix_environment: ${{ fromJson(needs.get_radix_environments.outputs.radix_environment) }}
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
outputs:
matrix: ${{ steps.set-matrix.outputs.list_of_environments_and_clusters_fmt }}
env:
path: terraform/clusters/${{ matrix.subscriptions }}/${{ matrix.radix_environment }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
run: |
cd ${{ env.path }}
mapfile -t radix_environments < <(ls .)
list_of_environments_and_clusters=$(for radix_environment in "${radix_environments[@]}"; do
if [[ -z $(ls "$radix_environment") ]]; then continue; fi
mapfile -t cluster_names < <(ls "$radix_environment")
for cluster_name in "${cluster_names[@]}"; do
jq -n \
--arg radix_environment "$radix_environment" \
--arg cluster_name "$cluster_name" \
'{radix_environment:$radix_environment, cluster_name:$cluster_name}';
done
done)
echo "list_of_environments_and_clusters_fmt=$(echo "$list_of_environments_and_clusters" | jq -sc .)" >> $GITHUB_OUTPUT
Terraform:
needs: [get_clusters, get_radix_environments, get_subscriptions]
name: Terraform
uses: ./.github/workflows/terraform.yml
strategy:
fail-fast: false
matrix:
cluster_info: ${{ fromJSON(needs.get_clusters.outputs.matrix) }}
radix_environment: ${{ fromJson(needs.get_radix_environments.outputs.radix_environment) }}
subscriptions: ${{ fromJson(needs.get_subscriptions.outputs.subscriptions) }}
with:
cluster_name: ${{ matrix.cluster_info.cluster_name }}
environment: operations
radix_environment: ${{ matrix.radix_environment }}
subscription: ${{ matrix.subscriptions }}
terraform_version: ~1.3.0
working_directory: terraform/clusters/${{ matrix.subscriptions }}/${{ matrix.radix_environment }}/${{ matrix.cluster_info.radix_environment }}/${{ matrix.cluster_info.cluster_name }}
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}