Create a gist now

Instantly share code, notes, and snippets.

@tk421 /azure.macfile
Last active Oct 19, 2015

Create and provision Windows Servers Automatically
# Create and provision Windows Servers Automatically
# http://blog.manageacloud.com/entry/azure-provision-windows-automatically
# You need azure xplat-cli installed and logged in before running this macfile
mac: 0.9.19
description: Azure Example
name: azure_demo # Infrastructure name
version: 1.1 # Infrastructure version
# Actions execute tasks which does not create resources in the cloud
actions:
# This action trigers a proof of concept of powershell bootstrap creating the C:\HelloWorld folder.
# The powershell script is stored here https://gist.githubusercontent.com/tk421/11a2ec3fad5bcce5de3f/raw/b0ca8770100905a39b2dadd0fec7d159ccc73874/createFolder.ps1
provision_windows_1:
bash: >
azure vm extension set macdemotest CustomScriptExtension Microsoft.Compute 1.4 -i '{"fileUris":["https://gist.githubusercontent.com/tk421/11a2ec3fad5bcce5de3f/raw/b0ca8770100905a39b2dadd0fec7d159ccc73874/createFolder.ps1"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -file createFolder.ps1" }' --json
# This actions waits until the server that we are creating is ReadyRole
wait_for_windows:
bash: >
while ! azure vm list | grep macdemotest | grep ReadyRole ; do echo "Waiting"; sleep 10; done;
# Macfile resources are tasks that creates items in the cloud (and it can also be destroyed)
resources:
# The VMs are create in a network.
network:
# we specify how the network is created. The parameters are defined in "infrastructures" section.
create bash:
azure network vnet create --location "infrastructure.param.location" infrastructure.param.name --json
# we specify how the network is destroyed. The parameters are defined in "infrastructures" section.
destroy bash:
azure network vnet delete -q infrastructure.param.name --json
# This resource creates a Windows VM
windows_vm:
create bash:
azure vm create --vm-name infrastructure.param.name
--location "infrastructure.param.location"
--virtual-network-name infrastructure.param.virtual-network-name
--rdp 3389
infrastructure.param.name
infrastructure.param.image infrastructure.param.username infrastructure.param.password
--json
destroy bash:
azure vm delete -q infrastructure.param.name --json
# Infrastructures is the section that actually creates items in the cloud.
# The order is preserved.
infrastructures:
# First of all creates the network. It is a dependency for the VM.
create_network:
resource: network
params:
location: "East US"
name: testnet
# Creation of the Windows VM
create_windows_vm:
resource: windows_vm
params:
name: macdemotest
location: "East US"
virtual-network-name: testnet
image: ad072bd3082149369c449ba5832401ae__Windows-Server-Remote-Desktop-Session-Host-on-Windows-Server-2012-R2-20150828-0350
username: username
password: MySafePassword01!
# We wait until the Windows VM is ready
wait_for_windows_vm:
action: wait_for_windows
# We Trigger the configuration of the VM.
provision_windows_vm:
action: provision_windows_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment