Skip to content

Instantly share code, notes, and snippets.

@caveatlector
Last active June 7, 2019 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caveatlector/a573d04659da02774cba8d10dbf590ff to your computer and use it in GitHub Desktop.
Save caveatlector/a573d04659da02774cba8d10dbf590ff to your computer and use it in GitHub Desktop.
Azure: create Windows VM (from existing disks)
#!/usr/bin/env bash
# Requires: az-cli
DATA_DISK= # Existing data disk (by name)
NSG= # Existing NSG (by name)
OS_DISK # Existing OS disk (by name)
PRIVATE_IP= # Available private IP address, e.g. 10.0.0.10
PUBLIC_IP= # Existing public IP address (by name)
RG_TARGET= # Existing resource group (by name) for deployment
RG_VNET= # Existing resource group (by name) containing existing VNet resource
SUBSCRIPTION=
VM_NAME= # VM name, also used for naming related resources (disks, NIC, PIP, etc.)
VM_SKU= # E.g. Standard_D2_v2
VNET= # Existing VNet (by name)
VNET_SUBNET= # Existing VNet subnet (by name)
az network public-ip create \
-g ${RG} \
-n ${VM_NAME}-pip \
--allocation-method Static
az network nic create \
-g ${RG} \
-n ${VM_NAME}-nic \
--network-security-group '/subscriptions/${SUBSCRIPTION}/resourceGroups/${RG_VNET}/providers/Microsoft.Network/networkSecurityGroups/${NSG}' \
--private-ip-address ${PRIVATE_IP} \
--public-ip-address ${PUBLIC_IP} \
--subnet '/subscriptions/${SUBSCRIPTION}/${RG_VNET}/providers/Microsoft.Network/virtualNetworks/${VNET}/subnets/${VNET_SUBNET}'
az vm create \
--resource-group ctrlitws-s-rg \
--name ${VM_NAME} \
--nics ${VM_NAME}-nic \
--size ${VM_SKU} \
--attach-data-disks /subscriptions/${SUBSCRIPTION}/resourceGroups/${RG}/providers/Microsoft.Compute/disks/${DATA_DISK} \
--attach-os-disk /subscriptions/${SUBSCRIPTION}/resourceGroups/${RG}/providers/Microsoft.Compute/disks/${OS_DISK} \
--os-type Windows \
--no-wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment