{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "The location where the resources will be deployed." } }, "vmName": { "type": "string", "defaultValue": "vm-gary-default" }, "vmSize": { "type": "string" }, "OSVersion": { "type": "string" }, "virtualNetworkName": { "type": "string", "defaultValue": "NotARealVNet1", "metadata": { "description": "New or Existing VNet Name" } }, "virtualNetworkResourceGroup": { "type": "string", "defaultValue": "fakerg", "metadata": { "description": "Resource group of the VNet" } }, "subnetName": { "type": "string", "metadata": { "description": "New or Existing subnet Name" } }, "vaultName": { "type": "string", "metadata": { "description": "The name of the keyvault that contains the secret." }, "defaultValue": "KeyvaultGary" }, "secretName": { "type": "string", "metadata": { "description": "The name of the secret." }, "defaultValue": "AdminPassword" }, "vaultResourceGroupName": { "type": "string", "metadata": { "description": "The name of the resource group that contains the keyvault." }, "defaultValue": "CustomScript" }, "vaultSubscription": { "type": "string", "defaultValue": "[subscription().subscriptionId]", "metadata": { "description": "The name of the subscription that contains the keyvault." } }, "scriptParameter": { "type": "string" } }, "resources": [ { "type": "Microsoft.Resources/deployments", "apiVersion": "2020-10-01", "name": "dynamicSecret", "properties": { "mode": "Incremental", "expressionEvaluationOptions": { "scope": "inner" }, "parameters": { "location": { "value": "[parameters('location')]" }, "vmName": { "value": "[parameters('vmName')]" }, "vmSize": { "value": "[parameters('vmSize')]" }, "OSVersion": { "value": "[parameters('OSVersion')]" }, "virtualNetworkName": { "value": "[parameters('virtualNetworkName')]" }, "virtualNetworkResourceGroup": { "value": "[parameters('virtualNetworkResourceGroup')]" }, "subnetName": { "value": "[parameters('subnetName')]" }, "scriptParameter": { "value": "[parameters('scriptParameter')]" }, "adminUsername": { "value": "admingary" }, "adminPassword": { "reference": { "keyVault": { "id": "[resourceId(parameters('vaultSubscription'), parameters('vaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('vaultName'))]" }, "secretName": "[parameters('secretName')]" } }, "storageAccountKey": { "reference": { "keyVault": { "id": "[resourceId(parameters('vaultSubscription'), parameters('vaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('vaultName'))]" }, "secretName": "storageAccountKey" } } }, "template": { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "adminUsername": { "type": "string", "metadata": { "description": "Username for the Virtual Machine." } }, "adminPassword": { "type": "securestring", "minLength": 12, "metadata": { "description": "Password for the Virtual Machine." } }, "storageAccountKey": { "type": "securestring" }, "OSVersion": { "type": "string", "defaultValue": "2019-Datacenter", "allowedValues": [ "2008-R2-SP1", "2012-Datacenter", "2012-R2-Datacenter", "2016-Nano-Server", "2016-Datacenter-with-Containers", "2016-Datacenter", "2019-Datacenter", "2019-Datacenter-Core", "2019-Datacenter-Core-smalldisk", "2019-Datacenter-Core-with-Containers", "2019-Datacenter-Core-with-Containers-smalldisk", "2019-Datacenter-smalldisk", "2019-Datacenter-with-Containers", "2019-Datacenter-with-Containers-smalldisk" ], "metadata": { "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version." } }, "vmSize": { "type": "string", "defaultValue": "Standard_D2_v3", "metadata": { "description": "Size of the virtual machine." } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for all resources." } }, "vmName": { "type": "string", "defaultValue": "simple-vm", "metadata": { "description": "Name of the virtual machine." } }, "virtualNetworkName": { "type": "string", "defaultValue": "abcde", "metadata": { "description": "New or Existing VNet Name" } }, "virtualNetworkResourceGroup": { "type": "string", "metadata": { "description": "Resource group of the VNet" } }, "subnetName": { "type": "string", "metadata": { "description": "New or Existing subnet Name" } }, "scriptFile": { "type": "string", "defaultValue": "https://customscriptsgary.blob.core.windows.net/scripts/RunThis.ps1" }, "scriptName": { "type": "string", "defaultValue": "RunThis.ps1" }, "scriptParameter": { "type": "string" } }, "variables": { "nicName": "[concat(parameters('vmName'), '-NIC')]", "vnetId": "[resourceId(parameters('virtualNetworkResourceGroup'),'Microsoft.Network/virtualNetworks',parameters('virtualNetworkName'))]", "subnetId": "[concat(variables('vnetId'),'/subnets/',parameters('subnetName'))]" }, "resources": [ { "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2020-06-01", "name": "[variables('nicName')]", "location": "[parameters('location')]", "dependsOn": [], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "subnet": { "id": "[variables('subnetId')]" } } } ] } }, { "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2020-06-01", "name": "[parameters('vmName')]", "location": "[parameters('location')]", "dependsOn": [ "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" ], "properties": { "hardwareProfile": { "vmSize": "[parameters('vmSize')]" }, "osProfile": { "computerName": "[parameters('vmName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "[parameters('OSVersion')]", "version": "latest" }, "osDisk": { "createOption": "FromImage", "managedDisk": { "storageAccountType": "StandardSSD_LRS" } }, "dataDisks": [ { "diskSizeGB": 1023, "lun": 0, "createOption": "Empty" } ] }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" } ] }, "diagnosticsProfile": { "bootDiagnostics": { "enabled": false } } } }, { "type": "Microsoft.Compute/virtualMachines/extensions", "name": "[concat(parameters('vmName'),'/CustomScriptExtension')]", "apiVersion": "2015-05-01-preview", "location": "[resourceGroup().location]", "dependsOn": [ "[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]" ], "properties": { "publisher": "Microsoft.Compute", "type": "CustomScriptExtension", "protectedSettings": { "fileUris": [ "[parameters('scriptFile')]" ], "storageAccountName": "customscriptsgary", "storageAccountKey": "[parameters('storageAccountKey')]" }, "typeHandlerVersion": "1.7", "autoUpgradeMinorVersion": true, "settings": { "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ', parameters('scriptName'), ' ', parameters('scriptParameter'))]" } } } ], "outputs": { } } } } ], "outputs": { } }