Created
December 11, 2019 22:26
-
-
Save lrakai/35e4cc26780c61663665107ccb912951 to your computer and use it in GitHub Desktop.
Template causing PowerShell to block on startup until custom script extension completes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"virtualMachineName": { | |
"type": "string", | |
"defaultValue": "ca-lab-vm" | |
}, | |
"virtualMachineSize": { | |
"type": "string", | |
"defaultValue": "Standard_B2ms" | |
}, | |
"adminUsername": { | |
"type": "string", | |
"defaultValue": "student" | |
}, | |
"virtualNetworkName": { | |
"type": "string", | |
"defaultValue": "ca-lab-vnet" | |
}, | |
"osDiskType": { | |
"type": "string", | |
"defaultValue": "StandardSSD_LRS" | |
}, | |
"networkInterfaceName": { | |
"type": "string", | |
"defaultValue": "ca-lab-vm001" | |
}, | |
"networkSecurityGroupName": { | |
"type": "string", | |
"defaultValue": "ca-lab-vm-nsg" | |
}, | |
"adminPassword": { | |
"type": "string", | |
"defaultValue": "1Cloud_Academy_Labs!" | |
}, | |
"diagnosticsStorageAccountName": { | |
"type": "string", | |
"defaultValue": "calabdiag" | |
}, | |
"diagnosticsStorageAccountType": { | |
"type": "string", | |
"defaultValue": "Standard_LRS" | |
}, | |
"diagnosticsStorageAccountKind": { | |
"type": "string", | |
"defaultValue": "Storage" | |
}, | |
"addressPrefix": { | |
"type": "string", | |
"defaultValue": "10.0.0.0/24" | |
}, | |
"subnetName": { | |
"type": "string", | |
"defaultValue": "default" | |
}, | |
"subnetPrefix": { | |
"type": "string", | |
"defaultValue": "10.0.0.0/24" | |
}, | |
"publicIpAddressName": { | |
"type": "string", | |
"defaultValue": "ca-lab-vm-ip" | |
}, | |
"publicIpAddressType": { | |
"type": "string", | |
"defaultValue": "Dynamic" | |
} | |
}, | |
"variables": { | |
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]", | |
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]", | |
"diagnosticsStorageAccountName": "[toLower(replace(concat(parameters('diagnosticsStorageAccountName'), resourceGroup().name),'-', ''))]" | |
}, | |
"resources": [ | |
{ | |
"name": "[parameters('virtualMachineName')]", | |
"type": "Microsoft.Compute/virtualMachines", | |
"apiVersion": "2019-07-01", | |
"location": "[resourceGroup().location]", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]", | |
"[concat('Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]" | |
], | |
"properties": { | |
"osProfile": { | |
"computerName": "[parameters('virtualMachineName')]", | |
"adminUsername": "[parameters('adminUsername')]", | |
"adminPassword": "[parameters('adminPassword')]", | |
"windowsConfiguration": { | |
"enableAutomaticUpdates": false, | |
"provisionVmAgent": true | |
} | |
}, | |
"hardwareProfile": { | |
"vmSize": "[parameters('virtualMachineSize')]" | |
}, | |
"storageProfile": { | |
"imageReference": { | |
"publisher": "MicrosoftWindowsServer", | |
"offer": "WindowsServer", | |
"sku": "2016-Datacenter-smalldisk", | |
"version": "latest" | |
}, | |
"osDisk": { | |
"createOption": "fromImage", | |
"managedDisk": { | |
"storageAccountType": "[parameters('osDiskType')]" | |
} | |
}, | |
"dataDisks": [] | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]" | |
} | |
] | |
}, | |
"diagnosticsProfile": { | |
"bootDiagnostics": { | |
"enabled": true, | |
"storageUri": "[concat('https://', variables('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]" | |
} | |
} | |
}, | |
"resources": [ | |
{ | |
"apiVersion": "2018-06-01", | |
"type": "extensions", | |
"name": "provision", | |
"location": "[resourceGroup().location]", | |
"dependsOn": [ | |
"[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]" | |
], | |
"tags": { | |
"displayName": "provision-vm" | |
}, | |
"properties": { | |
"publisher": "Microsoft.Compute", | |
"type": "CustomScriptExtension", | |
"typeHandlerVersion": "1.9", | |
"autoUpgradeMinorVersion": true, | |
"settings": { | |
"fileUris": [ | |
"https://raw.githubusercontent.com/cloudacademy/azure-lab-provisioners/master/keyvault-diskencryption-lab/bootstrap.ps1" | |
] | |
}, | |
"protectedSettings": { | |
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File bootstrap.ps1 -user ',parameters('adminUsername'),' -password ',parameters('adminPassword'))]" | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"name": "[variables('diagnosticsStorageAccountName')]", | |
"type": "Microsoft.Storage/storageAccounts", | |
"apiVersion": "2019-06-01", | |
"location": "[resourceGroup().location]", | |
"properties": {}, | |
"kind": "[parameters('diagnosticsStorageAccountKind')]", | |
"sku": { | |
"name": "[parameters('diagnosticsStorageAccountType')]" | |
} | |
}, | |
{ | |
"name": "[parameters('virtualNetworkName')]", | |
"type": "Microsoft.Network/virtualNetworks", | |
"apiVersion": "2016-12-01", | |
"location": "[resourceGroup().location]", | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"[parameters('addressPrefix')]" | |
] | |
}, | |
"subnets": [ | |
{ | |
"name": "[parameters('subnetName')]", | |
"properties": { | |
"addressPrefix": "[parameters('subnetPrefix')]" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"name": "[parameters('networkInterfaceName')]", | |
"type": "Microsoft.Network/networkInterfaces", | |
"apiVersion": "2016-09-01", | |
"location": "[resourceGroup().location]", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]", | |
"[concat('Microsoft.Network/publicIpAddresses/', parameters('publicIpAddressName'))]", | |
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]" | |
], | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig1", | |
"properties": { | |
"subnet": { | |
"id": "[variables('subnetRef')]" | |
}, | |
"privateIPAllocationMethod": "Dynamic", | |
"publicIpAddress": { | |
"id": "[resourceId(resourceGroup().name,'Microsoft.Network/publicIpAddresses', parameters('publicIpAddressName'))]" | |
} | |
} | |
} | |
], | |
"networkSecurityGroup": { | |
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]" | |
} | |
} | |
}, | |
{ | |
"name": "[parameters('publicIpAddressName')]", | |
"type": "Microsoft.Network/publicIpAddresses", | |
"apiVersion": "2016-09-01", | |
"location": "[resourceGroup().location]", | |
"properties": { | |
"publicIpAllocationMethod": "[parameters('publicIpAddressType')]" | |
} | |
}, | |
{ | |
"name": "[parameters('networkSecurityGroupName')]", | |
"type": "Microsoft.Network/networkSecurityGroups", | |
"apiVersion": "2016-09-01", | |
"location": "[resourceGroup().location]", | |
"properties": { | |
"securityRules": [ | |
{ | |
"name": "default-allow-rdp", | |
"properties": { | |
"priority": 1000, | |
"sourceAddressPrefix": "*", | |
"protocol": "TCP", | |
"destinationPortRange": "3389", | |
"access": "Allow", | |
"direction": "Inbound", | |
"sourcePortRange": "*", | |
"destinationAddressPrefix": "*" | |
} | |
} | |
] | |
} | |
} | |
], | |
"outputs": { | |
"adminUsername": { | |
"type": "string", | |
"value": "[parameters('adminUsername')]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment