I am getting error -
New-AzDisk : The provided gallery image: /subscriptions/44328f0f-3fad-40a5-ae95-390f5b1a0d8c/resourceGroups/co-np-eastu
s-Spectrum-OSImages-rg/providers/Microsoft.Compute/galleries/co_np_eastus_spectrum_os_images/images/Ubuntu_22.04_Baseli
ne_Hardened/versions/0.0.1 supports creation of OS disk only with SecurityType as TrustedLaunch.
ErrorCode: BadRequest
ErrorMessage: The provided gallery image: /subscriptions/44328f0f-3fad-40a5-ae95-390f5b1a0d8c/resourceGroups/co-np-east
us-Spectrum-OSImages-rg/providers/Microsoft.Compute/galleries/co_np_eastus_spectrum_os_images/images/Ubuntu_22.04_Basel
ine_Hardened/versions/0.0.1 supports creation of OS disk only with SecurityType as TrustedLaunch.
ErrorTarget:
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 76746fcd-3c1a-4c73-93c3-68ab6369f571
At C:\azagent_work\1\s\Export-AzureComputeGalleryImageVersion.ps1:51 char:13
- $Disk = New-AzDisk `
-
- CategoryInfo : CloseError: (:) [New-AzDisk], ComputeCloudException
- FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmDisk
Running this script in the agent VM.And i have checked the agent VM security type It's already Trusted Launch. So i am not able to find why i am getting this error.
While running this script in Azure Devops Pipeline:
param(
$ComputeGalleryName,
$ComputeGalleryResourceGroupName,
$ImageDefinitionName,
$ImageVersionName
)
$ErrorActionPreference = 'Stop'
$DiskPrefix = "disk-$($ImageDefinitionName)-"
$Location = (Get-AzResourceGroup -Name $ComputeGalleryResourceGroupName).Location
# Gets the Image Version ID
$ImageVersion = Get-AzGalleryImageVersion `
-GalleryImageDefinitionName $ImageDefinitionName `
-GalleryName $ComputeGalleryName `
-ResourceGroupName $ComputeGalleryResourceGroupName `
-Name $ImageVersionName
# Gets the OS Type
$OsType = (Get-AzGalleryImageDefinition `
-GalleryImageDefinitionName $ImageDefinitionName `
-GalleryName $ComputeGalleryName `
-ResourceGroupName $ComputeGalleryResourceGroupName).OsType
$ImageDisksCount = $ImageVersion.StorageProfile.OsDiskImage.Count + $ImageVersion.StorageProfile.DataDiskImages.Count
Write-Output "Image Disks Count: $($ImageDisksCount)"
for($i = 0; $i -lt $ImageDisksCount; $i++)
{
$GalleryImageReference = if($i -eq 0)
{
@{Id = $ImageVersion.Id}
}
else{
@{Id = $ImageVersion.Id; Lun = $($i - 1)}
}
# Creates a Disk Configuration for a Managed Disk using the Image Version in the Compute Gallery
$DiskConfig = New-AzDiskConfig `
-Location $Location `
-CreateOption FromImage `
-GalleryImageReference $GalleryImageReference `
-OsType $OsType
# Creates a Managed Disk using the Image Version in the Compute Gallery
$Disk = New-AzDisk `
-Disk $DiskConfig `
-ResourceGroupName $ComputeGalleryResourceGroupName `
-DiskName ($DiskPrefix + $i.ToString())
Write-Output "Disk: $($Disk)"
# Creates a URI with a SAS Token to download the VHD of the Managed Disk
$DiskAccess = Grant-AzDiskAccess `
-ResourceGroupName $Disk.ResourceGroupName `
-DiskName $Disk.Name `
-Access 'Read' `
-DurationInSecond 14400
# Downloads the VHD using 10 concurrent network calls and validates the MD5 hash
Get-AzStorageBlobContent `
-AbsoluteUri $DiskAccess.AccessSAS `
-Destination "f:\Temp\$($Disk.Name).vhd"
# Revokes the SAS Token to download the VHD
Revoke-AzDiskAccess `
-ResourceGroupName $Disk.ResourceGroupName `
-DiskName $Disk.Name
# Deletes the Managed Disk
Remove-AzDisk `
-ResourceGroupName $Disk.ResourceGroupName `
-DiskName $Disk.Name `
-Force
}