Skip to content

Commit 41b35e3

Browse files
authored
Create createresources.sh
Adding Bash Shell based Script for Creating Resources.
1 parent d437e24 commit 41b35e3

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

deploy/az/createresources.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
CreateGroup()
4+
{
5+
echo Creating resource group $resource_group in '$location'
6+
az group create --name $resource_group --location $location
7+
} # end of system_info
8+
9+
10+
11+
deployresources()
12+
{
13+
echo Deploying ARM template '$path_and_filename.json' in resource group $resource_group
14+
az group deployment create --resource-group $resource_group --parameters @$path_and_filename.parameters.json --template-file $path_and_filename.json
15+
}
16+
17+
Error_Usage()
18+
{
19+
echo ""
20+
echo Usage:
21+
echo create-resources arm-file resource-group-name [-c location]
22+
echo arm-file: Path to ARM template WITHOUT .json extension. An parameter file with same name plus '.parameters' MUST exist in same folder
23+
echo resource-grop-name: Name of the resource group to use or create
24+
echo -c: If appears means that resource group must be created. If -c is specified, must use enter location
25+
echo ""
26+
echo Examples:
27+
echo "1 create-resources path_and_filename testgroup (Deploys path_and_filename.json with parameters specified in path_and_filename.parameters.json file)."
28+
echo "2 create-resources path_and_filename newgroup -c westus (Deploys path_and_filename.json (with parameters specified in path_and_filename.parameters.json file) in a NEW resource group named newgroup in the westus location)"
29+
}
30+
31+
32+
33+
if [ $# -le 1 ]; then
34+
Error_Usage
35+
exit 1
36+
fi
37+
if [ "$1" == "" ]; then
38+
echo "path_and_filename is empty"
39+
Error_Usage
40+
exit 1
41+
fi
42+
43+
if [ "$2" == "" ]; then
44+
echo "Resource Group is empty"
45+
Error_Usage
46+
exit 1
47+
fi
48+
49+
if [ ! -f "$1.json" ]; then
50+
echo "$1.json doesn't exist"
51+
exit 1
52+
fi
53+
54+
if [ ! -f "$2.parameters.json" ]; then
55+
echo "$2.parameters.json doesn't exist"
56+
exit 1
57+
fi
58+
59+
60+
path_and_filename=$1
61+
resource_group=$2
62+
63+
64+
if [ "$3" == "-c" ]; then
65+
echo "Resource Group needs to be created"
66+
if [ "$4" == "" ]; then
67+
echo "but Resource Group name is missing"
68+
Error_Usage
69+
exit 1
70+
else
71+
location=$4
72+
CreateGroup
73+
fi
74+
75+
fi
76+
# if NOT $3.==-c. GOTO deployresources
77+
deployresources
78+
79+
echo "all finished successfully"

0 commit comments

Comments
 (0)