Skip to content

Commit c3ab110

Browse files
authored
azurerm_shared_image_version - Adapt upcoming breaking changes for Azure Compute Gallery Image Version (#28954)
* update api version of galleryimageversions * add code * fix lint
1 parent 4ae3f0d commit c3ab110

45 files changed

Lines changed: 174 additions & 21 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎internal/services/compute/client/client.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplications"
2323
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryapplicationversions"
2424
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages"
25-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
2625
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/gallerysharingupdate"
2726
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-03-01/virtualmachineruncommands"
2827
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-04-02/disks"
28+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
2929
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/availabilitysets"
3030
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/dedicatedhostgroups"
3131
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-03-01/dedicatedhosts"

‎internal/services/compute/helpers.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sort"
88

99
"github.com/hashicorp/go-azure-helpers/lang/pointer"
10-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
10+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
1111
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2024-07-01/virtualmachinescalesets"
1212
"github.com/hashicorp/go-version"
1313
)

‎internal/services/compute/helpers_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/hashicorp/go-azure-helpers/lang/pointer"
11-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
11+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
1212
)
1313

1414
func TestSortVersions_valid(t *testing.T) {

‎internal/services/compute/shared_image_resource.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1919
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
2020
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimages"
21-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
21+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
2222
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
2323
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
2424
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"

‎internal/services/compute/shared_image_version_data_source.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1414
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1515
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
16-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
16+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
1717
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
1818
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
1919
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"

‎internal/services/compute/shared_image_version_resource.go‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎internal/services/compute/shared_image_version_resource_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/hashicorp/go-azure-helpers/lang/pointer"
1313
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots"
14-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
14+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
1515
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1616
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1717
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"

‎internal/services/compute/shared_image_versions_data_source.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1212
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1313
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
14-
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions"
14+
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions"
1515
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
1616
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate"
1717
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"

vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/README.md renamed to vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions/README.md

Lines changed: 3 additions & 3 deletions

vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-03/galleryimageversions/client.go renamed to vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-07-03/galleryimageversions/client.go

File renamed without changes.

0 commit comments

Comments
 (0)