at 23.11-beta 1.2 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3set -x 4 5image="${1}" 6location="westus2" 7group="nixos-test-vm" 8vm_size="Standard_D2s_v3"; os_size=42; 9 10# ensure group 11az group create --location "westus2" --name "${group}" 12group_id="$(az group show --name "${group}" -o tsv --query "[id]")" 13 14# (optional) identity 15if ! az identity show -n "${group}-identity" -g "${group}" &>/dev/stderr; then 16 az identity create --name "${group}-identity" --resource-group "${group}" 17fi 18 19# (optional) role assignment, to the resource group, bad but not really great alternatives 20identity_id="$(az identity show --name "${group}-identity" --resource-group "${group}" -o tsv --query "[id]")" 21principal_id="$(az identity show --name "${group}-identity" --resource-group "${group}" -o tsv --query "[principalId]")" 22until az role assignment create --assignee "${principal_id}" --role "Owner" --scope "${group_id}"; do sleep 1; done 23 24# boot vm 25az vm create \ 26 --name "${group}-vm" \ 27 --resource-group "${group}" \ 28 --assign-identity "${identity_id}" \ 29 --size "${vm_size}" \ 30 --os-disk-size-gb "${os_size}" \ 31 --image "${image}" \ 32 --admin-username "${USER}" \ 33 --location "westus2" \ 34 --storage-sku "Premium_LRS" \ 35 --ssh-key-values "$(ssh-add -L)" 36