Skip to content

Commit

Permalink
azurerm_shared_image - support for the disk_controller_type_nvme_enab…
Browse files Browse the repository at this point in the history
…led property (#26370)
  • Loading branch information
mweibel authored Sep 20, 2024
1 parent 4d3585d commit f8ccc7a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/services/compute/shared_image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"),
Expand Down
49 changes: 49 additions & 0 deletions internal/services/compute/shared_image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/shared_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down

0 comments on commit f8ccc7a

Please sign in to comment.