-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuteDeploy.sh
More file actions
executable file
·61 lines (45 loc) · 1.66 KB
/
executeDeploy.sh
File metadata and controls
executable file
·61 lines (45 loc) · 1.66 KB
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
#!/bin/bash
# Stop on errors, unset variables, and pass back the error code
set -eu pipefail
# Script to deploy bicep resources to Azure
# Assumes runner is already logged into Azure and has contribute role
# Set the environment (dev, test, prod) and region (used to name resources)
DEPLOY_ENV='dev'
DEPLOY_LOC='westus3'
# Resource group name (Bicep will create the group if not already existing)
RG_NAME="rg-vmtest-$DEPLOY_ENV-$DEPLOY_LOC"
# Set the admin username and ssh key to currently logged in user
ADMIN_USER=$USER
ADMIN_SSH_KEY="$(cat ~/.ssh/id_rsa.pub)"
# Set the IP address range to whitelist
# Default to current external IP
IP_WHITELIST_RANGE=$(dig +short myip.opendns.com @resolver1.opendns.com)/32
# Create unique name for deployment
deploymentName='WD_Deployment_'$DEPLOY_ENV'_'$DEPLOY_LOC'_'$(date +"%Y%m%d%H%M%S")
echo "New deployment: $deploymentName"
# Show active subscription
echo ''
echo 'Active Subscription: '
echo ''
az account show -o table
# Deploy
echo ''
echo "Testing Deployment"
echo ''
DEPLOY_CMD="az deployment sub create --name $deploymentName --location $DEPLOY_LOC --template-file main.bicep --parameters environ=$DEPLOY_ENV location=$DEPLOY_LOC \
adminUsername=$ADMIN_USER adminSshKey=\"$ADMIN_SSH_KEY\" sshIpAddressRange=\"$IP_WHITELIST_RANGE\" resourceGroupName=$RG_NAME"
echo $DEPLOY_CMD
eval "$DEPLOY_CMD -w"
# Ask for conf
read -p "Continue with deploy (y/n)?" CONT
if [ "$CONT" != "y" ]; then
exit 0
fi
echo ''
echo 'Deploying...'
echo ''
eval "$DEPLOY_CMD"
echo ''
echo "Deployment complete into resource group $RG_NAME"
echo 'Public IP address of VM:'
az deployment sub show -n $deploymentName --query properties.outputs.vmPipIp.value