-
Notifications
You must be signed in to change notification settings - Fork 3
/
dns-zone-link.sh
executable file
·34 lines (30 loc) · 1.4 KB
/
dns-zone-link.sh
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
#!/bin/bash
set -e
wait-for-node-resource-group() {
NODE_RESOURCE_GROUP=$(az aks show -g ${AKS_RESOURCE_GROUP} -n ${AKS_CLUSTER_NAME} -o json 2>/dev/null | jq -r '.nodeResourceGroup')
while [ "${NODE_RESOURCE_GROUP}" == "" ]; do
echo "Waiting for node resource group..."
sleep 5
NODE_RESOURCE_GROUP=$(az aks show -g ${AKS_RESOURCE_GROUP} -n ${AKS_CLUSTER_NAME} -o json 2>/dev/null | jq -r '.nodeResourceGroup')
done
}
wait-for-private-dns-zone() {
length=$(az network private-dns zone list -g ${NODE_RESOURCE_GROUP} -o json 2>/dev/null | jq '. | length')
while [[ $length -eq 0 ]]; do
echo "Waiting for private DNS zone..."
sleep 5
length=$(az network private-dns zone list -g ${NODE_RESOURCE_GROUP} -o json 2>/dev/null | jq '. | length')
done
}
wait-for-node-resource-group
NODE_RESOURCE_GROUP=$(az aks show -g ${AKS_RESOURCE_GROUP} -n ${AKS_CLUSTER_NAME} -o json 2>/dev/null | jq -r '.nodeResourceGroup')
wait-for-private-dns-zone
ZONE_NAME=$(az network private-dns zone list -g ${NODE_RESOURCE_GROUP} -o json | jq -r '.[0].name')
echo "Get the private DNS Zone ${ZONE_NAME}"
az network private-dns link vnet create -o json \
-g ${NODE_RESOURCE_GROUP} \
-n private-dns-link \
--registration-enabled false \
--zone-name ${ZONE_NAME} \
--virtual-network ${DNS_VNET}
echo "Private DNS Zone ${ZONE_NAME} has been linked to VNet ${DNS_VNET}."