Skip to content

Latest commit

 

History

History
55 lines (47 loc) · 4.29 KB

vs2017.md

File metadata and controls

55 lines (47 loc) · 4.29 KB

Build the VS2017 Image

Create required Azure resources

  1. Open a PowerShell console window.
  2. Get the ID of the Azure subscription into which you will deploy the VM image. You can display all of your subscription IDs by running Login-AzureRmAccount and then Get-AzureRmSubscription.
  3. In the script below, replace <YOUR_SUBSCRIPTION_ID> on the top line with your subscription ID obtained above.
  4. Run your modified script in this directory of the cloned vsts-image-generation repo: images\win
  5. For future use, record the script (that sets variable values) that is output at the end of this script. You can use this in the future to set the correct variable values before running Packer.
  6. If you need to re-run this script, delete the resource group it creates (i.e. billgvs2017image), and delete the service principal (app registration) it creates (i.e. billgvs2017sp).
$subscriptionId = "<YOUR_SUBSCRIPTION_ID>"
Login-AzureRmAccount
Set-AzureRmContext -Subscription $subscriptionId
$rgName = $env:UserName + "vs2017image"
$location = "East US"
New-AzureRmResourceGroup -Name $rgName -Location $location
$storageAccountName = $rgName
New-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $storageAccountName -Location $location -SkuName "Standard_LRS"
$spDisplayName = $env:UserName + "vs2017sp"
$spClientSecret = "P@ssw0rd!"
$sp = New-AzureRmADServicePrincipal -DisplayName $spDisplayName -Password (ConvertTo-SecureString $spClientSecret -AsPlainText -Force)
$spAppId = $sp.ApplicationId
$spClientId = $sp.ApplicationId
$spObjectId = $sp.Id
Sleep 40
New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $spAppId
$sub = Get-AzureRmSubscription -SubscriptionId $subscriptionId
$tenantId = $sub.TenantId
"", "Note this variable-setting script for running Packer with these Azure resources in the future:", "==============================================================================================", "`$spClientId = `"$spClientId`"", "`$spClientSecret = `"$spClientSecret`"", "`$subscriptionId = `"$subscriptionId`"", "`$tenantId = `"$tenantId`"", "`$spObjectId = `"$spObjectId`"", "`$location = `"$location`"", "`$rgName = `"$rgName`"", "`$storageAccountName = `"$storageAccountName`"", ""

Use Packer to build and deploy the VM image template

  1. Open a PowerShell console window.
  2. Verify that Packer is in your path by typing packer --version.
  3. Run the variable-setting script that was output by the Create required Azure resources script above.
  4. Run the Packer command line below, which uses the variables set in the previous step. This command will take approximately 8.5 hours to complete.
packer.exe build -var "client_id=$($spClientId)" -var "client_secret=$($spClientSecret)" -var "subscription_id=$($subscriptionId)" -var "tenant_id=$($tenantId)" -var "object_id=$($spObjectId)" -var "location=$($location)" -var "resource_group=$($rgName)" -var "storage_account=$($storageAccountName)" vs2017-Server2016-Azure.json

Create a VM based on the template created by Packer

  1. At the end of the output from running Packer above is a URL to the VM resource template with a read access token. It ends with .json plus a query string. Note this URL.
  2. Create a new Network Interface with a public IP address in the Azure resource group created above. Note the Resource ID of the Network Interface (visible in its Properties tab on the Azure Portal). It begins with /subscriptions/<YOUR_SUBSCRIPTION_ID>/.
  3. As shown below, create a VM instance from the resource template. You will be prompted to enter the resource ID of the network interface you created above.
    $deploymentName = $env:UserName + "vs2017imagedeploy"
    $templatePath = "https://mystorageaccount.blob.core.windows.net/system/Microsoft.Compute/Images/images/packer-vmTemplate.d7085fc7-ae8c-4ec9-a21b-e91af1a37c2f.json?sv=2017-04-17&ss=bqtf&srt=sco&sp=rwdlacup&se=2018-01-25T22:14:54Z&sig=ZFX%2F1%2B5zgr3f%2BRzY9nc49VmAOH4vYXRZX34qO9yfH1%3D"
    New-AzureRmResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templatePath
  4. After the VM is created, remote into it using its public IP address. You can test the installed tools or install the VSTS agent and connect it to your VSTS account.