azure-powershell
azure-powershell copied to clipboard
Issues using New-AzImageBuilderTemplate to load from json
Description
I'm having trouble using New-AzImageBuilderTemplate to load my json templates. The error seems to indicate the module cannot extract parameters. Specifically, it seems to fail at extracting the replicationRegions
parameter. The parameter is filled correctly (and is the same region as the target gallery per doc.
I am simply filling in our own parameters from the quickstart template here, and adding our own customizers, the latter of which have no bearing on failing validation like this. The only major structural change was to strip this down to just the resources
block. Again, documentation is either out of date or unclear on proper use of AIB but this seems to be required to get even this far.
The redacted template is pasted here:
aib-gen-20h2-0712-redacted.txt
Script or Debug output
PS /home/barry/clouddrive/Template> New-AzImageBuilderTemplate -ImageTemplateName AIB-NetTest -JsonTemplatePath
aib-gen-20h2-0712.json -ResourceGroupName *
DEBUG: 6:32:44 PM - GetAzureRMContextCommand end processing.
DEBUG: [CmdletBeginProcessing]: Starting command
DEBUG: CmdletBeginProcessing:
DEBUG: CmdletProcessRecordStart:
DEBUG: [CmdletProcessRecordAsyncStart]: Created new QosEvent for command 'New-AzImageBuilderTemplate_Create'
DEBUG: CmdletProcessRecordAsyncStart:
DEBUG: CmdletGetPipeline:
DEBUG: CmdletBeforeAPICall:
DEBUG: URLCreated: /subscriptions/*/resourceGroups/*/providers/Microsoft.VirtualMachineImages/imageTemplates/AIB-NetTest?api-version=2020-02-14
DEBUG: RequestCreated: /subscriptions/*/resourceGroups/*/providers/Microsoft.VirtualMachineImages/imageTemplates/AIB-NetTest?api-version=2020-02-14
DEBUG: HeaderParametersAdded:
DEBUG: BodyContentSet:
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
PUT
Absolute Uri:
https://management.azure.com/subscriptions/*/resourceGroups/*/providers/Microsoft.VirtualMachineImages/imageTemplates/AIB-NetTest?api-version=2020-02-14
Headers:
x-ms-unique-id : 7
x-ms-client-request-id : 83269924-4af4-414d-8092-8eb440f6d6b2
CommandName : Az.ImageBuilder.internal\New-AzImageBuilderTemplate
FullCommandName : New-AzImageBuilderTemplate_Create
ParameterSetName : __AllParameterSets
User-Agent : AzurePowershell/v8.1.0,PSVersion/v7.2.5,Az.ImageBuilder/0.1.2
Body:
{
"location": "northcentralus",
"tags": {
"userIdentity": "enabled",
"CostCenter": "0010137100"
},
"properties": {
"source": {
"type": "PlatformImage",
"publisher": "MicrosoftWindowsDesktop",
"offer": "windows-10",
"sku": "20h2-ent",
"version": "latest"
},
"vmProfile": {
"vmSize": "Standard_D8as_v4",
"osDiskSizeGB": 127
},
"customize": [
{
"type": "PowerShell",
"name": "GetAzCopy",
"inline": [
"Write-Host \"Copying AzCopy\"",
"New-Item -ItemType Directory -Path \"C:\\\" -Name TEMP",
"New-Item -ItemType Directory -Path \"C:\\TEMP\" -Name Apps",
"Invoke-WebRequest -URI \"https://aka.ms/downloadazcopy-v10-windows\" -OutFile \"C:\\TEMP\\azcopy.zip\"",
"Expand-Archive \"C:\\TEMP\\azcopy.zip\" \"C:\\TEMP\"",
"Copy-Item \"C:\\TEMP\\azcopy_windows_amd64_*\\azcopy.exe\\\" -Destination \"C:\\TEMP\"",
],
"runElevated": true,
"runAsSystem": true
},
{
"type": "PowerShell",
"name": "Disable Firewall",
"inline": [
"netsh advfirewall set domainprofile state off",
]
},
{
"type": "PowerShell",
"name": "Enable Remote Connections",
"inline": [
"Set-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\" -Name fDenyTSConnections -Type DWORD -Value 0 -Force",
],
"runElevated": true,
"runAsSystem": true
},
{
"type": "PowerShell",
"name": "Timezone Redirect",
"scriptUri": "https://raw.githubusercontent.com/bferg317/ImageBuilder/master/timezoneredirect.ps1",
"runElevated": true,
"runAsSystem": true
},
{
"type": "WindowsUpdate",
"updateLimit": 40
},
{
"type": "PowerShell",
"name": "Debug Placeholder",
"inline": [
"Write-Host \"C30\""
],
"runElevated": true,
"runAsSystem": true
},
{
"type": "PowerShell",
"name": "SysprepFix",
"scriptUri": "https://raw.githubusercontent.com/bferg317/ImageBuilder/master/sysprepfix.ps1",
"runElevated": true,
"runAsSystem": true
},
{
"type": "WindowsRestart",
"restartCheckCommand": "Write-Host 'Final reboot before capture.'",
"restartTimeout": "5m"
}
],
"distribute": [
{
"type": "SharedImage",
"runOutputName": "AIB-NetTest",
"artifactTags": {
"source": "wvd10",
"baseosimg": "windows10",
"workflow": "aib-general",
"CostCenter": "0010137100"
},
"galleryImageId": "/subscriptions/*/resourceGroups/*/providers/Microsoft.Compute/galleries/ImageBuilderGallery/images/AIB-NetTest"
}
],
"buildTimeoutInMinutes": 120
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/*/resourcegroups/*/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ImageBuilder": {}
}
}
}
DEBUG: BeforeCall:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-ratelimit-remaining-subscription-writes: 1197
x-ms-correlation-request-id : 8ef321eb-86f0-4d61-91d4-d0766db866e6
x-ms-request-id : 38e79b71-f766-4599-92bc-737d5aa755c8
Strict-Transport-Security : max-age=31536000; includeSubDomains
Server : nginx
x-ms-routing-request-id : EASTUS:20220712T183245Z:8ef321eb-86f0-4d61-91d4-d0766db866e6
X-Content-Type-Options : nosniff
Date : Tue, 12 Jul 2022 18:32:45 GMT
Body:
{
"code": "ValidationFailed",
"message": "Validation failed: 'ImageTemplate.properties.distribute[0]': Missing field 'replicationRegions'. Please review http://aka.ms/azvmimagebuildertmplref for details on fields required in the Image Builder Template."
}
DEBUG: ResponseCreated:
DEBUG: BeforeResponseDispatch:
New-AzImageBuilderTemplate_Create: /home/barry/.local/share/powershell/Modules/Az.ImageBuilder/0.2.0/custom/New-AzImagerBuilderTemplate.ps1:257
Line |
257 | Az.ImageBuilder.internal\New-AzImageBuilderTemplate @PSBo …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Validation failed: 'ImageTemplate.properties.distribute[0]': Missing field
| 'replicationRegions'. Please review http://aka.ms/azvmimagebuildertmplref for details on
| fields required in the Image Builder Template.
DEBUG: [Finally]: Getting exception 'Microsoft.Azure.Commands.Common.Exceptions.AzPSCloudException: InternalException' from response
DEBUG: Finally:
DEBUG: CmdletAfterAPICall:
DEBUG: [CmdletProcessRecordAsyncEnd]: Finish HTTP process
DEBUG: CmdletProcessRecordAsyncEnd:
DEBUG: CmdletProcessRecordEnd:
DEBUG: AzureQoSEvent: Module: Az.ImageBuilder:0.1.2; CommandName: New-AzImageBuilderTemplate_Create; PSVersion: 7.2.5; IsSuccess: False; Duration: 00:00:00; Exception: InternalException;
DEBUG: Finish sending metric.
DEBUG: CmdletEndProcessing:
PS /home/barry/clouddrive/Template>
Environment data
PS /home/barry/clouddrive/Template> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.5
PSEdition Core
GitCommitId 7.2.5
OS Linux 5.4.0-1085-azure #90~18.04.1-Ubuntu SMP Fri Jun 10 18:32:22 UTC 2022
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
PS /home/barry/clouddrive/Template> Get-Module Az*
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.9.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clea…
Script 4.29.0 Az.Compute {Add-AzImageDataDisk, Add-AzVhd, Add-AzV…
Script 0.2.0 Az.ImageBuilder {Get-AzImageBuilderRunOutput, Get-AzImag…
Script 4.18.0 Az.Network {Add-AzApplicationGatewayAuthenticationC…
Script 6.0.1 Az.Resources {Export-AzResourceGroup, Export-AzTempla…
Script 4.7.0 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-…
Script 0.0.0.10 AzureAD.Standard.Preview {Add-AzureADApplicationOwner, Add-AzureA…
Script 0.9.3 AzurePSDrive
Error output
New-AzImageBuilderTemplate_Create: /home/barry/.local/share/powershell/Modules/Az.ImageBuilder/0.2.0/custom/New-AzImagerBuilderTemplate.ps1:257
Line |
257 | Az.ImageBuilder.internal\New-AzImageBuilderTemplate @PSBo …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Validation failed: 'ImageTemplate.properties.distribute[0]': Missing field
| 'replicationRegions'. Please review http://aka.ms/azvmimagebuildertmplref for details on
| fields required in the Image Builder Template.
Thanks for reporting. We suspect it is due to Az.ImageBuilder module is using old API version. We will upgrade API version and please try again. You can expect new version of that at the beginning of September.
Template solution is you can send request by Invoke-AzRestMethod
. But you cannot use your original template. You have to use the payload of request showing in debug log. The API version should be 2021-10-01 if you are using example from doc.
Confirm that upgrading API version will resolve this issue. I tried API 2022-02-14 with json file below. replicationRegions is sent successfully in new API version.
{
"location": "northcentralus",
"tags": {
"userIdentity": "enabled",
"CostCenter": "*"
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/*/resourcegroups/*/providers/Microsoft.ManagedIdentity/userAssignedIdentities/*": {}
}
},
"properties": {
"buildTimeoutInMinutes" : 120,
"source": {
"type": "PlatformImage",
"publisher": "MicrosoftWindowsDesktop",
"offer": "windows-10",
"sku": "20h2-ent",
"version": "latest"
},
"customize": [
{
"type": "PowerShell",
"name": "GetAzCopy",
"runElevated": true,
"runAsSystem": true,
"inline": [
"Write-Host \"Copying AzCopy\"",
"New-Item -ItemType Directory -Path \"C:\\\" -Name TEMP",
"New-Item -ItemType Directory -Path \"C:\\TEMP\" -Name Apps",
"Invoke-WebRequest -URI \"https://aka.ms/downloadazcopy-v10-windows\" -OutFile \"C:\\TEMP\\azcopy.zip\"",
"Expand-Archive \"C:\\TEMP\\azcopy.zip\" \"C:\\TEMP\"",
"Copy-Item \"C:\\TEMP\\azcopy_windows_amd64_*\\azcopy.exe\\\" -Destination \"C:\\TEMP\""
]
},
{
"type": "PowerShell",
"name": "Disable Firewall",
"inline": [
"netsh advfirewall set domainprofile state off"
]
},
{
"type": "PowerShell",
"name": "Enable Remote Connections",
"runElevated": true,
"runAsSystem": true,
"inline": [
"Set-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\" -Name fDenyTSConnections -Type DWORD -Value 0 -Force"
]
},
{
"type": "PowerShell",
"name": "Copy Test Script",
"runElevated": true,
"runAsSystem": true,
"inline": [
"New-Item -ItemType Directry -Path C:\\PerrigoAppInstalls",
"AzCopy .\\Copyfiles.vbs C:\\PerrigoAppInstalls"
]
},
{
"type": "PowerShell",
"name": "Timezone Redirect",
"runElevated": true,
"runAsSystem": true,
"scriptUri": "https://raw.githubusercontent.com/bferg317/ImageBuilder/master/timezoneredirect.ps1"
},
{
"type": "WindowsUpdate",
"searchCriteria": "IsInstalled=0",
"filters": [
"exclude:$_.Title -like \"*Preview*\"",
"include:$true"
],
"updateLimit": 40
},
{
"type": "PowerShell",
"name": "Debug Placeholder",
"runElevated": true,
"runAsSystem": true,
"inline": [
"Write-Host \"C30\""
]
},
{
"type": "PowerShell",
"name": "SysprepFix",
"runElevated": true,
"runAsSystem": true,
"scriptUri": "https://raw.githubusercontent.com/bferg317/ImageBuilder/master/sysprepfix.ps1"
},
{
"type": "WindowsRestart",
"restartCheckCommand": "Write-Host 'Final reboot before capture.'",
"restartTimeout": "5m"
}
],
"distribute":
[
{
"type": "SharedImage",
"galleryImageId": "/subscriptions/*/resourceGroups/*/providers/Microsoft.Compute/galleries/*/images/*-image",
"runOutputName": "AIB-NetTest",
"artifactTags": {
"source": "wvd10",
"baseosimg": "windows10",
"workflow": "aib-general",
"CostCenter": "0010137100"
},
"replicationRegions": [
"northcentralus"
]
}
]
}
}
Please expect this issue fixed in Az.ImageBuilder 0.3.0. It will be release on Sept 6th.