From 41b35e309b34eb19d51f04e2099a4b7a91c01003 Mon Sep 17 00:00:00 2001 From: Avinash Barnwal Date: Thu, 7 Dec 2017 21:02:25 +0530 Subject: [PATCH] Create createresources.sh Adding Bash Shell based Script for Creating Resources. --- deploy/az/createresources.sh | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 deploy/az/createresources.sh diff --git a/deploy/az/createresources.sh b/deploy/az/createresources.sh new file mode 100644 index 000000000..d2b465e4e --- /dev/null +++ b/deploy/az/createresources.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +CreateGroup() +{ + echo Creating resource group $resource_group in '$location' + az group create --name $resource_group --location $location +} # end of system_info + + + +deployresources() +{ + echo Deploying ARM template '$path_and_filename.json' in resource group $resource_group + az group deployment create --resource-group $resource_group --parameters @$path_and_filename.parameters.json --template-file $path_and_filename.json +} + +Error_Usage() +{ + echo "" + echo Usage: + echo create-resources arm-file resource-group-name [-c location] + echo arm-file: Path to ARM template WITHOUT .json extension. An parameter file with same name plus '.parameters' MUST exist in same folder + echo resource-grop-name: Name of the resource group to use or create + echo -c: If appears means that resource group must be created. If -c is specified, must use enter location + echo "" + echo Examples: + echo "1 create-resources path_and_filename testgroup (Deploys path_and_filename.json with parameters specified in path_and_filename.parameters.json file)." + 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)" +} + + + +if [ $# -le 1 ]; then + Error_Usage + exit 1 +fi +if [ "$1" == "" ]; then + echo "path_and_filename is empty" + Error_Usage + exit 1 +fi + +if [ "$2" == "" ]; then + echo "Resource Group is empty" + Error_Usage + exit 1 +fi + +if [ ! -f "$1.json" ]; then + echo "$1.json doesn't exist" + exit 1 +fi + +if [ ! -f "$2.parameters.json" ]; then + echo "$2.parameters.json doesn't exist" + exit 1 +fi + + +path_and_filename=$1 +resource_group=$2 + + +if [ "$3" == "-c" ]; then + echo "Resource Group needs to be created" + if [ "$4" == "" ]; then + echo "but Resource Group name is missing" + Error_Usage + exit 1 + else + location=$4 + CreateGroup + fi + +fi +# if NOT $3.==-c. GOTO deployresources +deployresources + +echo "all finished successfully"