-
Notifications
You must be signed in to change notification settings - Fork 137
159 lines (141 loc) · 7.11 KB
/
IaC-bicep-AKSClusterOnly.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: 'IaC Deploy AKS Cluster only'
on:
workflow_dispatch:
inputs:
ENVIRONMENT:
description: 'A GitHub Environment to pull action secrets from'
required: true
type: environment
REGION:
description: 'The Azure region to deploy to'
required: true
default: westus2
clusterVnetResourceId:
description: 'The vnet resource ID (not uuid)'
required: true
ACRNAME:
description: 'The Name of the ACR resource'
required: true
type: string
clusterAdminAadGroupObjectId:
description: 'K8S Admin Azure AAD Group ObjectID'
required: true
type: string
a0008NamespaceReaderAadGroupObjectId:
description: 'K8S Reader Azure AAD Group ObjectID'
required: true
type: string
env:
event_sha: +refs/pull/${{ github.event.issue.number }}/merge
permissions:
id-token: write
contents: read
jobs:
prereqs:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.ENVIRONMENT }}
name: Prerequisite Checks
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "Parameter Check"
run: |
echo "Environment : ${{ github.event.inputs.ENVIRONMENT }}"
echo "vnet resource ID : ${{ github.event.inputs.clusterVnetResourceId }}"
echo "ACR : ${{ github.event.inputs.ACRNAME }}"
echo "K8S Admin Azure AAD Group ObjectID : ${{ github.event.inputs.clusterAdminAadGroupObjectId }}"
echo "K8S Reader Azure AAD Group ObjectID : ${{ github.event.inputs.a0008NamespaceReaderAadGroupObjectId }}"
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: "Check Preview Features"
shell: pwsh
run: |
write-output "Verifying required Resource Providers Features are registered"
$aksfeatures = az feature list --query "[?contains(name, 'Microsoft.ContainerService')]" | ConvertFrom-Json
$featureName='AKS-ExtensionManager'
write-output "-- $featureName"
$feature = $aksfeatures | Where-Object {$_.name -like "*$featureName"}
$feature.properties.state
if ($feature.properties.state -ne 'Registered') {
Write-Output $feature
Write-Error "$featureName NOT registered"
}
$featureName='EnableOIDCIssuerPreview'
write-output "-- $featureName"
$feature = $aksfeatures | Where-Object {$_.name -like "*$featureName"}
$feature.properties.state
if ($feature.properties.state -ne 'Registered') {
Write-Output $feature
Write-Error "$featureName NOT registered"
}
$featureName='AKS-AzureDefender'
write-output "-- $featureName"
$feature = $aksfeatures | Where-Object {$_.name -like "*$featureName"}
$feature.properties.state
if ($feature.properties.state -ne 'Registered') {
Write-Output $feature
Write-Error "$featureName NOT registered"
}
deployment:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.ENVIRONMENT }}
name: Deployment
needs: [prereqs]
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: "Cert Generation"
id: cert
run: |
export DOMAIN_NAME_AKS_BASELINE="contoso.com"
export CN="bicycle"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -out appgw.crt -keyout appgw.key -subj "/CN=${CN}.${DOMAIN_NAME_AKS_BASELINE}/O=Contoso Bicycle" -addext "subjectAltName = DNS:${CN}.${DOMAIN_NAME_AKS_BASELINE}" -addext "keyUsage = digitalSignature" -addext "extendedKeyUsage = serverAuth"
openssl pkcs12 -export -out appgw.pfx -in appgw.crt -inkey appgw.key -passout pass:
export APP_GATEWAY_LISTENER_CERTIFICATE_AKS_BASELINE=$(cat appgw.pfx | base64 | tr -d '\n')
echo "APP_GATEWAY_LISTENER_CERTIFICATE=$APP_GATEWAY_LISTENER_CERTIFICATE_AKS_BASELINE" >> $GITHUB_ENV
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -out traefik-ingress-internal-aks-ingress-tls.crt -keyout traefik-ingress-internal-aks-ingress-tls.key -subj "/CN=*.aks-ingress.${DOMAIN_NAME_AKS_BASELINE}/O=Contoso AKS Ingress"
export AKS_INGRESS_CONTROLLER_CERTIFICATE_BASE64_AKS_BASELINE=$(cat traefik-ingress-internal-aks-ingress-tls.crt | base64 | tr -d '\n')
echo "AKS_INGRESS_CONTROLLER_CERTIFICATE=$AKS_INGRESS_CONTROLLER_CERTIFICATE_BASE64_AKS_BASELINE" >> $GITHUB_ENV
- name: "test"
id: test
run: |
echo "${{ env.APP_GATEWAY_LISTENER_CERTIFICATE }}"
echo "${{ env.AKS_INGRESS_CONTROLLER_CERTIFICATE }}"
- name: "Deploy Cluster"
id: cluster
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.SUBSCRIPTION_ID }}
region: ${{ github.event.inputs.REGION }}
scope: subscription
template: ./IaC/bicep/rg-spoke/cluster.bicep
parameters: ./IaC/bicep/rg-spoke/cluster.parameters.json appGatewayListenerCertificate=${{ env.APP_GATEWAY_LISTENER_CERTIFICATE }} aksIngressControllerCertificate=${{ env.AKS_INGRESS_CONTROLLER_CERTIFICATE }} targetVnetResourceId=${{ github.event.inputs.clusterVnetResourceId }} clusterAdminAadGroupObjectId=${{ github.event.inputs.clusterAdminAadGroupObjectId }} a0008NamespaceReaderAadGroupObjectId=${{ github.event.inputs.a0008NamespaceReaderAadGroupObjectId }} vNetResourceGroup=rg-enterprise-networking-spokes-${{ github.event.inputs.REGION }} location=${{ github.event.inputs.REGION }} resourceGroupName=rg-BU0001A0008-${{ github.event.inputs.REGION }} gitOpsBootstrappingRepoBranch=${{ github.ref_name }}
failOnStdErr: false
deploymentName: carml-cluster-${{ github.event.inputs.REGION }}
- name: "Pull AKV_NAME"
id: akv_name
run: |
export AKV_NAME=$(az deployment group list -g rg-BU0001A0008-${{ github.event.inputs.REGION }} -o table| grep 'kv-aks'|awk '{print $1}')
echo "AKV_NAME=${AKV_NAME}" >> $GITHUB_ENV
echo "AKV Name extracted by querying is ${AKV_NAME}"
echo "aksIngressControllerPodManagedIdentityResourceId from bicep output is ${{ steps.cluster.outputs.aksIngressControllerPodManagedIdentityResourceId }}"
echo "AKV Name from bicep output is ${{ steps.cluster.outputs.keyVaultName }}"
- name: "Get KeyVault Name"
id: testName
run: |
echo "aksIngressControllerPodManagedIdentityResourceId from bicep output is ${{ steps.cluster.outputs.aksIngressControllerPodManagedIdentityResourceId }}"
echo "AKV Name from bicep output is ${{ steps.cluster.outputs.keyVaultName }}"