diff --git a/help/CreateImageAndAzureResources.md b/help/CreateImageAndAzureResources.md new file mode 100644 index 000000000..3684dfba9 --- /dev/null +++ b/help/CreateImageAndAzureResources.md @@ -0,0 +1,11 @@ +# Build an image. + +## Create required Azure resources and generate an image + +1. Generating required Azure resources and running a packer build for a targeted image is automated [here](../helpers/GenerateResourcesAndImage.ps1). + +## 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. For now, it seems like there is an [Az CLI bug](https://github.com/Azure/azure-cli/issues/5899) with specifying the template through a URI. So download the template locally and note the path of the template file. +1. Generating the required Azure resources and creating the VM is automated [here](../helpers/CreateAzureVMFromPackerTemplate.ps1). +1. After the VM is created, remote into it using its public IP address. You can test the installed tools or install the Azure Pipelines agent and connect it to your Azure DevOps organization. \ No newline at end of file diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index bc0e649fb..cf683ece6 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -61,6 +61,9 @@ Function GenerateResourcesAndImage { .PARAMETER Force Delete the resource group if it exists without user confirmation. + .PARAMETER GithubFeedToken + GitHub PAT to download tool packages from GitHub Package Registry + .EXAMPLE GenerateResourcesAndImage -SubscriptionId {YourSubscriptionId} -ResourceGroupName "shsamytest1" -ImageGenerationRepositoryRoot "C:\virtual-environments" -ImageType Ubuntu1604 -AzureLocation "East US" #> @@ -77,10 +80,18 @@ Function GenerateResourcesAndImage { [string] $AzureLocation, [Parameter(Mandatory = $False)] [int] $SecondsToWaitForServicePrincipalSetup = 30, + [Parameter(Mandatory = $True)] + [string] $GithubFeedToken, [Parameter(Mandatory = $False)] [Switch] $Force ) + if (([string]::IsNullOrEmpty($version))) + { + Write-Error "You have to specify valid GitHub PAT to dowload tool packages from GitHub Package Registry" + exit 0 + } + $builderScriptPath = Get-PackerTemplatePath -RepositoryRoot $ImageGenerationRepositoryRoot -ImageType $ImageType $ServicePrincipalClientSecret = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); $InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); @@ -155,5 +166,16 @@ Function GenerateResourcesAndImage { $tenantId = $sub.TenantId # "", "Note this variable-setting script for running Packer with these Azure resources in the future:", "==============================================================================================", "`$spClientId = `"$spClientId`"", "`$ServicePrincipalClientSecret = `"$ServicePrincipalClientSecret`"", "`$SubscriptionId = `"$SubscriptionId`"", "`$tenantId = `"$tenantId`"", "`$spObjectId = `"$spObjectId`"", "`$AzureLocation = `"$AzureLocation`"", "`$ResourceGroupName = `"$ResourceGroupName`"", "`$storageAccountName = `"$storageAccountName`"", "`$install_password = `"$install_password`"", "" - packer.exe build -on-error=ask -var "client_id=$($spClientId)" -var "client_secret=$($ServicePrincipalClientSecret)" -var "subscription_id=$($SubscriptionId)" -var "tenant_id=$($tenantId)" -var "object_id=$($spObjectId)" -var "location=$($AzureLocation)" -var "resource_group=$($ResourceGroupName)" -var "storage_account=$($storageAccountName)" -var "install_password=$($InstallPassword)" $builderScriptPath + packer.exe build -on-error=ask ` + -var "client_id=$($spClientId)" ` + -var "client_secret=$($ServicePrincipalClientSecret)" ` + -var "subscription_id=$($SubscriptionId)" ` + -var "tenant_id=$($tenantId)" ` + -var "object_id=$($spObjectId)" ` + -var "location=$($AzureLocation)" ` + -var "resource_group=$($ResourceGroupName)" ` + -var "storage_account=$($storageAccountName)" ` + -var "install_password=$($InstallPassword)" ` + -var "github_feed_token=$($GithubFeedToken)" ` + $builderScriptPath }