diff --git a/help/CreateImageAndAzureResources.md b/help/CreateImageAndAzureResources.md index 123d335cf..3401c1fce 100644 --- a/help/CreateImageAndAzureResources.md +++ b/help/CreateImageAndAzureResources.md @@ -12,6 +12,7 @@ After successful image generation, a snapshot of the temporary VM will be conver - `packer` - Can be downloaded from https://www.packer.io/downloads - `PowerShell 5.0 or higher` or `PSCore` for linux distributes. - `Azure CLI ` - https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest +- `Azure Powershell module` - https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-4.6.1 ### Azure DevOps self-hosted pool requirements To connect to a temporary VM packer use WinRM or SSH connections on public IP interfaces. @@ -31,7 +32,7 @@ Download `packer` from https://www.packer.io/downloads, or install it via Chocol choco install packer ``` -Install Azure CLI - https://docs.microsoft.com/ru-ru/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli. +Install Azure CLI - https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli. ``` Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi ``` diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index 321770949..31d48ee65 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -110,12 +110,12 @@ Function GenerateResourcesAndImage { $ServicePrincipalClientSecret = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); $InstallPassword = $env:UserName + [System.GUID]::NewGuid().ToString().ToUpper(); - Login-AzureRmAccount - Set-AzureRmContext -SubscriptionId $SubscriptionId + Connect-AzAccount + Set-AzContext -SubscriptionId $SubscriptionId $alreadyExists = $true; try { - Get-AzureRmResourceGroup -Name $ResourceGroupName + Get-AzResourceGroup -Name $ResourceGroupName Write-Verbose "Resource group was found, will delete and recreate it." } catch { @@ -126,8 +126,8 @@ Function GenerateResourcesAndImage { if ($alreadyExists) { if($Force -eq $true) { # Cleanup the resource group if it already exitsted before - Remove-AzureRmResourceGroup -Name $ResourceGroupName -Force - New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation + Remove-AzResourceGroup -Name $ResourceGroupName -Force + New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation } else { $title = "Delete Resource Group" $message = "The resource group you specified already exists. Do you want to clean it up?" @@ -146,13 +146,13 @@ Function GenerateResourcesAndImage { switch ($result) { - 0 { Remove-AzureRmResourceGroup -Name $ResourceGroupName -Force; New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation } + 0 { Remove-AzResourceGroup -Name $ResourceGroupName -Force; New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation } 1 { <# Do nothing #> } 2 { exit } } } } else { - New-AzureRmResourceGroup -Name $ResourceGroupName -Location $AzureLocation + New-AzResourceGroup -Name $ResourceGroupName -Location $AzureLocation } # This script should follow the recommended naming conventions for azure resources @@ -164,19 +164,19 @@ Function GenerateResourcesAndImage { $storageAccountName = $storageAccountName.Replace("-", "").Replace("_", "").Replace("(", "").Replace(")", "").ToLower() $storageAccountName += "001" - New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $storageAccountName -Location $AzureLocation -SkuName "Standard_LRS" + New-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $storageAccountName -Location $AzureLocation -SkuName "Standard_LRS" $spDisplayName = [System.GUID]::NewGuid().ToString().ToUpper() - $sp = New-AzureRmADServicePrincipal -DisplayName $spDisplayName -Password (ConvertTo-SecureString $ServicePrincipalClientSecret -AsPlainText -Force) + $sp = New-AzADServicePrincipal -DisplayName $spDisplayName -Password (ConvertTo-SecureString $ServicePrincipalClientSecret -AsPlainText -Force) $spAppId = $sp.ApplicationId $spClientId = $sp.ApplicationId $spObjectId = $sp.Id Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup - New-AzureRmRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $spAppId + New-AzRoleAssignment -RoleDefinitionName Contributor -ServicePrincipalName $spAppId Start-Sleep -Seconds $SecondsToWaitForServicePrincipalSetup - $sub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId + $sub = Get-AzSubscription -SubscriptionId $SubscriptionId $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`"", ""