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_managed_disk - Support optimized_frequent_attach_enabled and performance_plus_enabled #23241

Merged
merged 2 commits into from
Sep 13, 2023
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
25 changes: 23 additions & 2 deletions internal/services/compute/managed_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ func resourceManagedDisk() *pluginsdk.Resource {
Computed: true,
},

"optimized_frequent_attach_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"performance_plus_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
},

"source_uri": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -342,9 +355,11 @@ func resourceManagedDiskCreate(d *pluginsdk.ResourceData, meta interface{}) erro

props := &disks.DiskProperties{
CreationData: disks.CreationData{
CreateOption: createOption,
CreateOption: createOption,
PerformancePlus: pointer.To(d.Get("performance_plus_enabled").(bool)),
},
OsType: &osType,
OptimizedForFrequentAttach: pointer.To(d.Get("optimized_frequent_attach_enabled").(bool)),
OsType: &osType,
Encryption: &disks.Encryption{
Type: &encryptionTypePlatformKey,
},
Expand Down Expand Up @@ -702,6 +717,10 @@ func resourceManagedDiskUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
return fmt.Errorf("[ERROR] disk_iops_read_write, disk_mbps_read_write, disk_iops_read_only and disk_mbps_read_only are only available for UltraSSD disks and PremiumV2 disks")
}

if d.HasChange("optimized_frequent_attach_enabled") {
diskUpdate.Properties.OptimizedForFrequentAttach = pointer.To(d.Get("optimized_frequent_attach_enabled").(bool))
}

if d.HasChange("os_type") {
operatingSystemType := disks.OperatingSystemTypes(d.Get("os_type").(string))
diskUpdate.Properties.OsType = &operatingSystemType
Expand Down Expand Up @@ -1038,6 +1057,7 @@ func resourceManagedDiskRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("gallery_image_reference_id", galleryImageReferenceId)
d.Set("image_reference_id", imageReferenceId)

d.Set("performance_plus_enabled", creationData.PerformancePlus)
d.Set("source_resource_id", creationData.SourceResourceId)
d.Set("source_uri", creationData.SourceUri)
d.Set("storage_account_id", creationData.StorageAccountId)
Expand All @@ -1048,6 +1068,7 @@ func resourceManagedDiskRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("disk_mbps_read_write", props.DiskMBpsReadWrite)
d.Set("disk_iops_read_only", props.DiskIOPSReadOnly)
d.Set("disk_mbps_read_only", props.DiskMBpsReadOnly)
d.Set("optimized_frequent_attach_enabled", props.OptimizedForFrequentAttach)
d.Set("os_type", string(pointer.From(props.OsType)))
d.Set("tier", props.Tier)
d.Set("max_shares", props.MaxShares)
Expand Down
89 changes: 89 additions & 0 deletions internal/services/compute/managed_disk_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,40 @@ func TestAccManagedDisk_update(t *testing.T) {
})
}

func TestAccManagedDisk_optimizedFrequentAttach(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test")
r := ManagedDiskResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.optimizedFrequentAttach(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
Config: r.empty(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func TestAccManagedDisk_performancePlus(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test")
r := ManagedDiskResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.performancePlus(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func TestAccManagedDisk_encryption(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test")
r := ManagedDiskResource{}
Expand Down Expand Up @@ -822,6 +856,61 @@ resource "azurerm_managed_disk" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (ManagedDiskResource) optimizedFrequentAttach(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_managed_disk" "test" {
name = "acctestd-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1"
optimized_frequent_attach_enabled = true

tags = {
environment = "acctest"
cost-center = "ops"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (ManagedDiskResource) performancePlus(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_managed_disk" "test" {
name = "acctestd-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
storage_account_type = "Premium_LRS"
create_option = "Empty"
disk_size_gb = "1024"
performance_plus_enabled = true
tags = {
environment = "acctest"
cost-center = "ops"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (ManagedDiskResource) requiresImport(data acceptance.TestData) string {
template := ManagedDiskResource{}.empty(data)
return fmt.Sprintf(`
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ The following arguments are supported:

~> **NOTE:** Setting logical sector size is supported only with `UltraSSD_LRS` disks and `PremiumV2_LRS` disks.

* `optimized_frequent_attach_enabled` - (Optional) Specifies whether this Managed Disk should be optimized for frequent disk attachments (where a disk is attached/detached more than 5 times in a day). Defaults to `false`.

-> **Note:** Setting `optimized_frequent_attach_enabled` to `true` causes the disks to not align with the fault domain of the Virtual Machine, which can have operational implications.

* `performance_plus_enabled` - (Optional) Specifies whether Performance Plus is enabled for this Managed Disk. Defaults to `false`. Changing this forces a new resource to be created.

-> **Note:** `performance_plus_enabled` can only be set to `true` when using a Managed Disk with an Ultra SSD.

* `os_type` - (Optional) Specify a value when the source of an `Import`, `ImportSecure` or `Copy` operation targets a source that contains an operating system. Valid values are `Linux` or `Windows`.

* `source_resource_id` - (Optional) The ID of an existing Managed Disk or Snapshot to copy when `create_option` is `Copy` or the recovery point to restore when `create_option` is `Restore`. Changing this forces a new resource to be created.
Expand Down
Loading