Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_shared_image - support for the disk_controller_type_nvme_enabled property #26370

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading