Skip to content

rgl/azure-windows-vm

Repository files navigation

an example azure ubuntu virtual machine

Usage (on a Ubuntu Desktop)

Install the tools:

./provision-tools.sh

Login into azure-cli:

az login

List the subscriptions:

az account list --all
az account show

Set the subscription:

export ARM_SUBSCRIPTION_ID="<YOUR-SUBSCRIPTION-ID>"
az account set --subscription "$ARM_SUBSCRIPTION_ID"

Review main.tf and maybe change the location variable.

Initialize terraform:

make terraform-init

Launch the example:

make terraform-apply

At VM initialization time a Custom Script Extension will run the provision.ps1 script to customize the VM and launch the example web application.

Get the initialization script status:

az vm get-instance-view \
    --resource-group rgl-windows-vm-example \
    --name app \
    --query instanceView.extensions

After VM initialization is done (the log is stored at c:\AzureData\provision-log.txt), test the app endpoint:

wget -qO- "http://$(terraform output --raw app_ip_address)/test"

You can also list all resources:

az resource list \
    --resource-group rgl-windows-vm-example \
    --output table

You can execute commands:

# NB unfortunately, run-command is somewhat limited. for example, it only
#    outputs last 4k of the command output.
#    see https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command#restrictions
az vm run-command invoke \
    --resource-group rgl-windows-vm-example \
    --name app \
    --command-id RunPowerShellScript \
    --scripts 'whoami /all' \
    > output.json \
    && jq -r '.value[].message' output.json \
    && rm output.json
az vm run-command invoke \
    --resource-group rgl-windows-vm-example \
    --name app \
    --command-id RunPowerShellScript \
    --scripts 'param([string]$name)' 'Write-Host "Hello $name!"' \
    --parameters 'name=Rui' \
    > output.json \
    && jq -r '.value[].message' output.json \
    && rm output.json

Destroy the example:

make terraform-destroy

Reference

About

an example azure windows virtual machine

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published