Ryan Conway
Ryan Conway

Reputation: 71

Error creating new disk on Azure from snapshot

I am want to create a new disk from an image called "python3" on Azure to use in a VM scale set. Here is the relevant code:

$BaseDiskName = "python3_disk_20210614"
$SnapshotName = "python3"

$snapshot = Get-AzSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName
$diskconfig = New-AzDiskConfig -Location $LocationName -SourceResourceId $snapshot.Id -CreateOption Copy
$newdisk = New-AzDisk $diskconfig -ResourceGroupName $ResourceGroupName -DiskName $BaseDiskName

When display the properties of $diskconfig, this is what I get:

ResourceGroupName            :
ManagedBy                    :
ManagedByExtended            :
Sku                          :
Zones                        :
TimeCreated                  :
OsType                       :
HyperVGeneration             :
CreationData                 : Microsoft.Azure.Management.Compute.Models.CreationData
DiskSizeGB                   :
DiskSizeBytes                :
UniqueId                     :
EncryptionSettingsCollection :
ProvisioningState            :
DiskIOPSReadWrite            :
DiskMBpsReadWrite            :
DiskIOPSReadOnly             :
DiskMBpsReadOnly             :
DiskState                    :
Encryption                   :
MaxShares                    :
ShareInfo                    :
Id                           :
Name                         :
Type                         :
Location                     : Central US
Tags                         :
NetworkAccessPolicy          :
DiskAccessId                 :
Tier                         :
BurstingEnabled              :

When running the last line of script, I get the following error:

*New-AzDisk : Resource python3 is not found. ErrorCode: NotFound ErrorMessage: Resource python3 is not found. ErrorTarget: StatusCode: 404 ReasonPhrase: Not Found OperationID : 37907fcd-b55b-4851-9c7e-43fdb187bbfe At V:\Modeling Software\computing\working\launch_VM - Copy.ps1:34 char:12

However, I can read and view the $diskconfig object which was loaded from the python3 image. How can python3 be not found when it was just used in the line above?

Upvotes: 0

Views: 936

Answers (1)

Ked Mardemootoo
Ked Mardemootoo

Reputation: 1595

As mentioned in the comments, you were missing the parameter -Disk right before parsing the variable $diskconfig in your command. It should just be changed to:

$newdisk = New-AzDisk -Disk $diskconfig -ResourceGroupName $ResourceGroupName -DiskName $BaseDiskName

Here's a reference to the Azure Documentation for the New-AzDisk cmdlet.

Upvotes: 1

Related Questions