@@ -17,7 +17,8 @@ import (
1717 "github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1818 "github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
1919 "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/images"
20- "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
20+ "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
21+ "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/virtualmachines"
2122 "github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
2223 "github.com/hashicorp/terraform-provider-azurerm/internal/clients"
2324 "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
@@ -249,8 +250,15 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{
249250 }
250251
251252 if v , ok := d .GetOk ("managed_image_id" ); ok {
252- version .Properties .StorageProfile .Source = & galleryimageversions.GalleryArtifactVersionFullSource {
253- Id : utils .String (v .(string )),
253+ _ , err := virtualmachines .ParseVirtualMachineID (v .(string ))
254+ if err == nil {
255+ version .Properties .StorageProfile .Source = & galleryimageversions.GalleryArtifactVersionFullSource {
256+ VirtualMachineId : utils .String (v .(string )),
257+ }
258+ } else {
259+ version .Properties .StorageProfile .Source = & galleryimageversions.GalleryArtifactVersionFullSource {
260+ Id : utils .String (v .(string )),
261+ }
254262 }
255263 }
256264
@@ -265,8 +273,8 @@ func resourceSharedImageVersionCreate(d *pluginsdk.ResourceData, meta interface{
265273 if v , ok := d .GetOk ("blob_uri" ); ok {
266274 version .Properties .StorageProfile .OsDiskImage = & galleryimageversions.GalleryDiskImage {
267275 Source : & galleryimageversions.GalleryDiskImageSource {
268- Id : pointer .To (d .Get ("storage_account_id" ).(string )),
269- Uri : pointer .To (v .(string )),
276+ StorageAccountId : pointer .To (d .Get ("storage_account_id" ).(string )),
277+ Uri : pointer .To (v .(string )),
270278 },
271279 }
272280 }
@@ -391,7 +399,13 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{})
391399 }
392400
393401 if source := props .StorageProfile .Source ; source != nil {
394- d .Set ("managed_image_id" , source .Id )
402+ if source .Id != nil {
403+ d .Set ("managed_image_id" , source .Id )
404+ }
405+
406+ if source .VirtualMachineId != nil {
407+ d .Set ("managed_image_id" , source .VirtualMachineId )
408+ }
395409 }
396410
397411 blobURI := ""
@@ -402,14 +416,23 @@ func resourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{})
402416
403417 osDiskSnapShotID := ""
404418 storageAccountID := ""
405- if props .StorageProfile .OsDiskImage != nil && props .StorageProfile .OsDiskImage .Source != nil && props .StorageProfile .OsDiskImage .Source .Id != nil {
406- sourceID := * props .StorageProfile .OsDiskImage .Source .Id
419+ if props .StorageProfile .OsDiskImage != nil && props .StorageProfile .OsDiskImage .Source != nil {
420+ sourceID := ""
421+ if props .StorageProfile .OsDiskImage .Source .Id != nil {
422+ sourceID = * props .StorageProfile .OsDiskImage .Source .Id
423+ }
424+
425+ if props .StorageProfile .OsDiskImage .Source .StorageAccountId != nil {
426+ sourceID = * props .StorageProfile .OsDiskImage .Source .StorageAccountId
427+ }
428+
407429 if blobURI == "" {
408430 osDiskSnapShotID = sourceID
409431 } else {
410432 storageAccountID = sourceID
411433 }
412434 }
435+
413436 d .Set ("os_disk_snapshot_id" , osDiskSnapShotID )
414437 d .Set ("storage_account_id" , storageAccountID )
415438
0 commit comments