-
Notifications
You must be signed in to change notification settings - Fork 3
/
deployTemplate.sh
executable file
·83 lines (70 loc) · 2.21 KB
/
deployTemplate.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
###################################################################################################
# Script Name: deployTemplate.sh
# Author: Jungho Kim
# Description: Validates then deploys an ARM template. It will look for an azureDeploy.json and
# azureDeploy.parameters.json then validate it and if valid, deploy it.
#
# Options:
#
# -g <resourceGroup>
# -n <deploymentName>
# -v if provided will only validate not deploy
#
#######################################################################################################
resourceGroup=''
deploymentName=''
template='azureDeploy.json'
parameters='azureDeploy.parameters.json'
justValidate=false
function usage {
echo "To validate and deploy: ./deployTemplate.sh -g <resourceGroup> -n <deploymentName>"
echo "To just validate: add the -v switch"
}
function validate_template {
echo "start validating template..."
azure group template validate -g "${resourceGroup}" -f "$template" -e "${parameters}"
if [ $? -ne 0 ]; then
echo "Template validation failed. See error."
exit 1
else
echo "template is valid."
fi
}
function deploy_template {
if ! $justValidate
then
echo "start deploying template..."
azure group deployment create -f "${template}" -e "$parameters" -g "${resourceGroup}" -n "${deploymentName}"
fi
if [ $? -ne 0 ]; then
echo "deployment failed. Check error messages."
exit 1;
fi
}
while getopts g:n:v opt; do
case $opt in
g)
resourceGroup=${OPTARG}
echo "resourceGroup --> $resourceGroup"
;;
n)
deploymentName=${OPTARG}
echo "deploymentName --> $deploymentName"
;;
v) #if true just validate and don't deploy'
justValidate=true;
echo "validation only set to ${justValidate}"
;;
\?) #invalid option
echo "${OPTARG} is not a valid option"
usage
exit 1
;;
esac
done
if [ -z "$resourceGroup" ] ;then echo "-g must be provided"; exit 1; fi
if [ -z "$deploymentName" ] ;then echo "-n must be provided"; exit 1; fi
validate_template
deploy_template
exit 0