You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

  1. #!/bin/bash
  2. CreateGroup()
  3. {
  4. echo Creating resource group $resource_group in '$location'
  5. az group create --name $resource_group --location $location
  6. } # end of CreateGroup()
  7. deployresources()
  8. {
  9. echo Deploying ARM template '$path_and_filename.json' in resource group $resource_group
  10. az group deployment create --resource-group $resource_group --parameters @$path_and_filename.parameters.json --template-file $path_and_filename.json
  11. } # end of deployresources
  12. Error_Usage()
  13. {
  14. echo ""
  15. echo Usage:
  16. echo create-resources arm-file resource-group-name [-c location]
  17. echo arm-file: Path to ARM template WITHOUT .json extension. An parameter file with same name plus '.parameters' MUST exist in same folder
  18. echo resource-grop-name: Name of the resource group to use or create
  19. echo -c: If appears means that resource group must be created. If -c is specified, must use enter location
  20. echo ""
  21. echo Examples:
  22. echo "1 create-resources path_and_filename testgroup (Deploys path_and_filename.json with parameters specified in path_and_filename.parameters.json file)."
  23. 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)"
  24. }
  25. if [ $# -le 1 ]; then
  26. Error_Usage
  27. exit 1
  28. fi
  29. if [ "$1" == "" ]; then
  30. echo "path_and_filename is empty"
  31. Error_Usage
  32. exit 1
  33. fi
  34. if [ "$2" == "" ]; then
  35. echo "Resource Group is empty"
  36. Error_Usage
  37. exit 1
  38. fi
  39. if [ ! -f "$1.json" ]; then
  40. echo "$1.json doesn't exist"
  41. exit 1
  42. fi
  43. if [ ! -f "$1.parameters.json" ]; then
  44. echo "$1.parameters.json doesn't exist"
  45. exit 1
  46. fi
  47. path_and_filename=$1
  48. resource_group=$2
  49. if [ "$3" == "-c" ]; then
  50. echo "Resource Group needs to be created"
  51. if [ "$4" == "" ]; then
  52. echo "but Resource Group name is missing"
  53. Error_Usage
  54. exit 1
  55. else
  56. location=$4
  57. CreateGroup
  58. fi
  59. fi
  60. deployresources
  61. echo "all resources finished successfully"