-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
66 lines (59 loc) · 1.9 KB
/
deploy.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
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
#!/bin/bash
# Variables
location='westeurope'
deploymentName='policy-deployment'
template="../bicep/main.bicep"
parameters="../bicep/main.parameters.json"
whatIf=1
validate=1
# Subscription id, subscription name, and tenant id of the current subscription
subscriptionId=$(az account show --query id --output tsv)
subscriptionName=$(az account show --query name --output tsv)
tenantId=$(az account show --query tenantId --output tsv)
if [[ $validate == 1 ]]; then
if [[ $whatIf == 1 ]]; then
# Execute a deployment What-If operation at resource group scope.
echo "Previewing changes deployed by [$template] Bicep template..."
az deployment sub what-if \
--name $deploymentName \
--location $location \
--template-file $template \
--parameters $parameters \
--parameters location=$location
if [[ $? == 0 ]]; then
echo "[$template] Bicep template validation succeeded"
else
echo "Failed to validate [$template] Bicep template"
exit
fi
else
# Validate the Bicep template
echo "Validating [$template] Bicep template..."
output=$(az deployment sub validate \
--name $deploymentName \
--location $location \
--template-file $template \
--parameters $parameters \
--parameters location=$location)
if [[ $? == 0 ]]; then
echo "[$template] Bicep template validation succeeded"
else
echo "Failed to validate [$template] Bicep template"
echo $output
exit
fi
fi
fi
# Deploy infrastructure
az deployment sub create \
--name $deploymentName \
--location $location \
--template-file $template \
--parameters $parameters \
--parameters location=$location
if [[ $? == 0 ]]; then
echo "[$deploymentName] deployment successfully created in the [$subscriptionName] subscription"
else
echo "Failed to create [$deploymentName] deployment in the [$subscriptionName] subscription"
exit -1
fi