From f8ccc7ae64cd2327c3eaa654790a0f3b98063583 Mon Sep 17 00:00:00 2001 From: Michael Weibel <307427+mweibel@users.noreply.github.com> Date: Fri, 20 Sep 2024 07:05:50 +0200 Subject: [PATCH] azurerm_shared_image - support for the disk_controller_type_nvme_enabled property (#26370) --- .../services/compute/shared_image_resource.go | 19 +++++++ .../compute/shared_image_resource_test.go | 49 +++++++++++++++++++ website/docs/r/shared_image.html.markdown | 2 + 3 files changed, 70 insertions(+) diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 207d7fdfdb37..2f277179507c 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -265,6 +265,12 @@ func resourceSharedImage() *pluginsdk.Resource { ForceNew: true, }, + "disk_controller_type_nvme_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + ForceNew: true, + }, + "tags": commonschema.Tags(), }, @@ -524,6 +530,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error cvmSupported := false acceleratedNetworkSupportEnabled := false hibernationEnabled := false + diskControllerTypeNVMEEnabled := false if features := props.Features; features != nil { for _, feature := range *features { if feature.Name == nil || feature.Value == nil { @@ -544,6 +551,10 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error if strings.EqualFold(*feature.Name, "IsHibernateSupported") { hibernationEnabled = strings.EqualFold(*feature.Value, "true") } + + if strings.EqualFold(*feature.Name, "DiskControllerTypes") { + diskControllerTypeNVMEEnabled = strings.Contains(*feature.Value, "NVMe") + } } } d.Set("confidential_vm_supported", cvmSupported) @@ -552,6 +563,7 @@ func resourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("trusted_launch_enabled", trustedLaunchEnabled) d.Set("accelerated_network_support_enabled", acceleratedNetworkSupportEnabled) d.Set("hibernation_enabled", hibernationEnabled) + d.Set("disk_controller_type_nvme_enabled", diskControllerTypeNVMEEnabled) } return tags.FlattenAndSet(d, model.Tags) @@ -744,6 +756,13 @@ func expandSharedImageFeatures(d *pluginsdk.ResourceData) *[]galleryimages.Galle }) } + if d.Get("disk_controller_type_nvme_enabled").(bool) { + features = append(features, galleryimages.GalleryImageFeature{ + Name: pointer.To("DiskControllerTypes"), + Value: pointer.To("SCSI, NVMe"), + }) + } + if tvmSupported := d.Get("trusted_launch_supported").(bool); tvmSupported { features = append(features, galleryimages.GalleryImageFeature{ Name: pointer.To("SecurityType"), diff --git a/internal/services/compute/shared_image_resource_test.go b/internal/services/compute/shared_image_resource_test.go index 6710783052b2..0240a9da1e8c 100644 --- a/internal/services/compute/shared_image_resource_test.go +++ b/internal/services/compute/shared_image_resource_test.go @@ -200,6 +200,20 @@ func TestAccSharedImage_withHibernationEnabled(t *testing.T) { }) } +func TestAccSharedImage_withDiskControllerTypeNVMeEnabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") + r := SharedImageResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.withDiskControllerTypeNVMeEnabled(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccSharedImage_description(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") r := SharedImageResource{} @@ -770,6 +784,41 @@ resource "azurerm_shared_image" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } +func (SharedImageResource) withDiskControllerTypeNVMeEnabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_shared_image_gallery" "test" { + name = "acctestsig%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_shared_image" "test" { + name = "acctestimg%d" + gallery_name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + os_type = "Linux" + + disk_controller_type_nvme_enabled = true + + identifier { + publisher = "AccTesPublisher%d" + offer = "AccTesOffer%d" + sku = "AccTesSku%d" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + func (SharedImageResource) description(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/shared_image.html.markdown b/website/docs/r/shared_image.html.markdown index 13b14078bdcb..0d794987f9a0 100644 --- a/website/docs/r/shared_image.html.markdown +++ b/website/docs/r/shared_image.html.markdown @@ -108,6 +108,8 @@ The following arguments are supported: * `hibernation_enabled` - (Optional) Specifies if the Shared Image supports hibernation. Changing this forces a new resource to be created. +* `disk_controller_type_nvme_enabled` - (Optional) Specifies if the Shared Image supports NVMe disks. Changing this forces a new resource to be created. + * `tags` - (Optional) A mapping of tags to assign to the Shared Image. ---