From 96af3c46950c70abcb4264ea2137285574cdb9b2 Mon Sep 17 00:00:00 2001 From: Crowell Date: Tue, 4 Apr 2017 11:55:53 -0700 Subject: [PATCH] works! --- .../azuredeploy.parameters.json | 20 +++++++++++++ .../vch-iaas-deployment/deploy.ps1 | 16 ++++++++--- .../vch-iaas-deployment/template.json | 28 +++++++++++++------ 3 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 json_deployment_templates/vch-iaas-deployment/azuredeploy.parameters.json diff --git a/json_deployment_templates/vch-iaas-deployment/azuredeploy.parameters.json b/json_deployment_templates/vch-iaas-deployment/azuredeploy.parameters.json new file mode 100644 index 0000000..4b8f16f --- /dev/null +++ b/json_deployment_templates/vch-iaas-deployment/azuredeploy.parameters.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "adminPassword": { + "reference": { + "keyVault": { + "id": "/subscriptions/4830d36a-e5da-4f38-8647-b8ca702c1b1d/resourceGroups/vchds-root-rg/providers/Microsoft.KeyVault/vaults/vchDsKeyVault" + }, + "secretName": "VmAdminPassword" + } + } + // "dnsLabelPrefix": { + // "value": "GEN-UNIQUE" + // }, + // "windowsOSVersion": { + // "value": "2012-R2-Datacenter" + // } + } +} \ No newline at end of file diff --git a/json_deployment_templates/vch-iaas-deployment/deploy.ps1 b/json_deployment_templates/vch-iaas-deployment/deploy.ps1 index eef4d38..20c2006 100644 --- a/json_deployment_templates/vch-iaas-deployment/deploy.ps1 +++ b/json_deployment_templates/vch-iaas-deployment/deploy.ps1 @@ -1,8 +1,16 @@ Set-Location -Path $PSScriptRoot $template_path = Join-Path -Path $PSScriptRoot -ChildPath "template.json" $template_path = "template.json" -Login-AzureRmAccount +$parameter_path = "azuredeploy.parameters.json" +# Login-AzureRmAccount # Set-AzureRmContext -SubscriptionID {your-subscription-ID} -New-AzureRmResourceGroup -Name rg1 -Location "canadacentral" -Test-AzureRmResourceGroupDeployment -ResourceGroupName rg1 -TemplateFile $template_path -Verbose -Debug -New-AzureRmResourceGroupDeployment -Name rg1 -ResourceGroupName rg1 -TemplateFile $template_path \ No newline at end of file + +$Secret = Read-Host -AsSecureString -Prompt "Enter VM local admin password. `nIt will save/OVERWRITE secret: VmAdminPassword `nin Key vault: vchDsKeyVault" +# save pass word to Azure Key Vault +Set-AzureKeyVaultSecret -VaultName 'vchDsKeyVault' -Name 'VmAdminPassword' -SecretValue $Secret +# enable Key Vault for template deployment +Set-AzureRmKeyVaultAccessPolicy -VaultName 'vchDsKeyVault' -EnabledForTemplateDeployment + +New-AzureRmResourceGroup -Name rg2 -Location "canadacentral" +Test-AzureRmResourceGroupDeployment -ResourceGroupName rg2 -TemplateFile $template_path -TemplateParameterFile $parameter_path -Verbose -Debug +New-AzureRmResourceGroupDeployment -Name gcdeployment -ResourceGroupName rg2 -TemplateFile $template_path -TemplateParameterFile $parameter_path diff --git a/json_deployment_templates/vch-iaas-deployment/template.json b/json_deployment_templates/vch-iaas-deployment/template.json index b247665..0c6c4c5 100644 --- a/json_deployment_templates/vch-iaas-deployment/template.json +++ b/json_deployment_templates/vch-iaas-deployment/template.json @@ -29,6 +29,19 @@ "vmSize": "Standard_DS13_v2" } + }, + "adminName": { + "type": "string", + "defaultValue": "Floater1", + "metadata": { + "description": "VM admin user name." + } + }, + "adminPassword": { + "type": "securestring", + "metadata": { + "description": "VM admin password." + } } }, "variables": { @@ -41,7 +54,7 @@ "type": "Microsoft.Network/virtualNetworks", "name": "[parameters('virtualNetworkName')]", "apiVersion": "2016-03-30", - "location": "[parameters('location')]", + "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ @@ -70,7 +83,7 @@ "type": "Microsoft.Network/networkSecurityGroups", "name": "[variables('adNsgName')]", "apiVersion": "2016-03-30", - "location": "[parameters('location')]", + "location": "[resourceGroup().location]", "properties": { "securityRules": [{ "name": "rdp-rule", @@ -100,7 +113,7 @@ "count": "[parameters('workLoadAd')['count']]" }, "apiVersion": "2016-04-30-preview", - "location": "[parameters('location')]", + "location": "[resourceGroup().location]", "properties": { "hardwareProfile": { "vmSize": "[parameters('workLoadAd')['vmSize']]" @@ -125,7 +138,8 @@ }, "osProfile": { "computerName": "[concat(variables('adVmName'), copyIndex())]", - "adminUsername": "Floater1", + "adminUsername": "[parameters('adminName')]", + "adminPassword": "[parameters('adminPassword')]", "windowsConfiguration": { "provisionVMAgent": true, "enableAutomaticUpdates": true @@ -158,7 +172,7 @@ }, "name": "[concat(variables('adVmName'), copyIndex(),'Nic')]", "apiVersion": "2016-03-30", - "location": "[parameters('location')]", + "location": "[resourceGroup().location]", "properties": { "ipConfigurations": [{ "name": "ipconfig1", @@ -182,8 +196,6 @@ } }, "dependsOn": [ - // "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]", - // "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('adVmName'), copyIndex(),'Nic'))]", "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('adVmName'), copyIndex(),'Pip'))]", "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]", "[resourceId('Microsoft.Network/networkSecurityGroups', variables('adNsgName'))]" @@ -198,7 +210,7 @@ "count": "[parameters('workLoadAd')['count']]" }, "apiVersion": "2016-03-30", - "location": "[parameters('location')]", + "location": "[resourceGroup().location]", "properties": { "publicIPAllocationMethod": "Static", "idleTimeoutInMinutes": 4,