Skip to content

Instantly share code, notes, and snippets.

@pichuang
Last active January 15, 2025 02:17
Show Gist options
  • Save pichuang/4a6a83811fd76ba88c04c13593d8e3de to your computer and use it in GitHub Desktop.
Save pichuang/4a6a83811fd76ba88c04c13593d8e3de to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# The script is used to create Azure Bastion in TaiwanNorth region.
# And will create a public IP for Azure Bastion without any issues
#
# Steps:
# 1. Open Cloud Shell in Azure Portal https://shell.azure.com/
# 2. Donwload the script to Cloud Shell wget https://gist.githubusercontent.com/pichuang/4a6a83811fd76ba88c04c13593d8e3de/raw/1a47cb059df9e1f27e0937ea99a7e398c323737e/deploy-azure-bastion.sh
# 3. Modify the variables in the script
# 4. Run the script `bash deploy-azure-bastion.sh`
#
# Variables
#
# Azure Subscription
SUBSCRIPTION_ID="subscription-sandbox-any-projects"
# Azure Public IP
RESOURCE_GROUP_BASTION_PUBLICIP="rg-bastion-twn"
BASTION_PUBLICIP_NAME="pip-bastion-123-twn"
# Azure Bastion
RESOURCE_GROUP_BASTION="rg-bastion-twn"
BASTION_NAME="bastion-123-twn"
HUB_VNET_NAME="vnet-bastion-test-twn"
az account set --subscription=$SUBSCRIPTION_ID
#
# Create Public IP
#
# https://learn.microsoft.com/en-us/cli/azure/network/public-ip?view=azure-cli-latest#az-network-public-ip-create
az network public-ip create --name $BASTION_PUBLICIP_NAME \
--resource-group $RESOURCE_GROUP_BASTION_PUBLICIP \
--allocation-method Static \
--ddos-protection-mode Disabled \
--location TaiwanNorth \
--sku Standard \
--version IPv4 \
--tier Regional
#
# Create Azure Bastion
#
# https://learn.microsoft.com/en-us/cli/azure/network/bastion?view=azure-cli-latest#az-network-bastion-create
PIP_BASTION_RESOURCE_ID=$(az network public-ip show --name $BASTION_PUBLICIP_NAME \
--resource-group $RESOURCE_GROUP_BASTION_PUBLICIP \
--query id --out tsv)
az network bastion create --name $BASTION_NAME \
--public-ip-address $PIP_BASTION_RESOURCE_ID \
--resource-group $RESOURCE_GROUP_BASTION \
--vnet-name $HUB_VNET_NAME \
--location TaiwanNorth \
--sku Standard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment