diff --git a/internal/services/compute/managed_disk_resource.go b/internal/services/compute/managed_disk_resource.go index cba17100bcec..1966e01e6c21 100644 --- a/internal/services/compute/managed_disk_resource.go +++ b/internal/services/compute/managed_disk_resource.go @@ -81,6 +81,16 @@ func resourceManagedDisk() *pluginsdk.Resource { }, false), }, + "logical_sector_size": { + Type: pluginsdk.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validation.IntInSlice([]int{ + 512, + 4096}), + Computed: true, + }, + "source_uri": { Type: pluginsdk.TypeString, Optional: true, @@ -247,8 +257,13 @@ func resourceManagedDiskCreate(d *pluginsdk.ResourceData, meta interface{}) erro diskMBps := int64(v.(int)) props.DiskMBpsReadWrite = &diskMBps } - } else if d.HasChange("disk_iops_read_write") || d.HasChange("disk_mbps_read_write") { - return fmt.Errorf("[ERROR] disk_iops_read_write and disk_mbps_read_write are only available for UltraSSD disks") + + if v, ok := d.GetOk("logical_sector_size"); ok { + props.CreationData.LogicalSectorSize = utils.Int32(int32(v.(int))) + } + + } else if d.HasChange("disk_iops_read_write") || d.HasChange("disk_mbps_read_write") || d.HasChange("logical_sector_size") { + return fmt.Errorf("[ERROR] disk_iops_read_write, disk_mbps_read_write and logical_sector_size are only available for UltraSSD disks") } if createOption == compute.Import { @@ -634,6 +649,9 @@ func resourceManagedDiskRead(d *pluginsdk.ResourceData, meta interface{}) error if props := resp.DiskProperties; props != nil { if creationData := props.CreationData; creationData != nil { d.Set("create_option", string(creationData.CreateOption)) + if creationData.LogicalSectorSize != nil { + d.Set("logical_sector_size", creationData.LogicalSectorSize) + } imageReferenceID := "" if creationData.ImageReference != nil && creationData.ImageReference.ID != nil { diff --git a/internal/services/compute/managed_disk_resource_test.go b/internal/services/compute/managed_disk_resource_test.go index f15a1ceef99b..4e1f6c893748 100644 --- a/internal/services/compute/managed_disk_resource_test.go +++ b/internal/services/compute/managed_disk_resource_test.go @@ -445,6 +445,21 @@ func TestAccAzureRMManagedDisk_update_withMaxShares(t *testing.T) { }) } +func TestAccAzureRMManagedDisk_create_withLogicalSectorSize(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") + r := ManagedDiskResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.create_withLogicalSectorSize(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (ManagedDiskResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.ManagedDiskID(state.ID) if err != nil { @@ -1356,6 +1371,32 @@ resource "azurerm_managed_disk" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } +func (ManagedDiskResource) create_withLogicalSectorSize(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 = "UltraSSD_LRS" + create_option = "Empty" + disk_size_gb = "256" + logical_sector_size = 512 + zones = ["1"] + tags = { + environment = "acctest" + cost-center = "ops" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + func (ManagedDiskResource) update_withMaxShares(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/guides/3.0-overview.html.markdown b/website/docs/guides/3.0-overview.html.markdown index 72493df5a51d..68620b24eeb2 100644 --- a/website/docs/guides/3.0-overview.html.markdown +++ b/website/docs/guides/3.0-overview.html.markdown @@ -66,4 +66,4 @@ More information about the new Data Sources and Resources for App Service coming --- -Since version 3.0 of the Azure Provider is being iteratively developed, more information will be added to this page over time - since this documentation is versioned, we recommend checking [the latest version of this document](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/3.0-overview). \ No newline at end of file +Since version 3.0 of the Azure Provider is being iteratively developed, more information will be added to this page over time - since this documentation is versioned, we recommend checking [the latest version of this document](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/3.0-overview). diff --git a/website/docs/r/application_insights_smart_detection_rule.html.markdown b/website/docs/r/application_insights_smart_detection_rule.html.markdown index 3b6ddd924a8a..7b2179cce94e 100644 --- a/website/docs/r/application_insights_smart_detection_rule.html.markdown +++ b/website/docs/r/application_insights_smart_detection_rule.html.markdown @@ -71,4 +71,4 @@ Application Insights Smart Detection Rules can be imported using the `resource i ```shell terraform import azurerm_application_insights_smart_detection_rule.rule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.insights/components/mycomponent1/SmartDetectionRule/myrule1 -``` \ No newline at end of file +``` diff --git a/website/docs/r/managed_disk.html.markdown b/website/docs/r/managed_disk.html.markdown index 982861a51e86..a1ac49c0a03c 100644 --- a/website/docs/r/managed_disk.html.markdown +++ b/website/docs/r/managed_disk.html.markdown @@ -109,6 +109,10 @@ The following arguments are supported: * `image_reference_id` - (Optional) ID of an existing platform/marketplace disk image to copy when `create_option` is `FromImage`. +* `logical_sector_size` - (Optional) Logical Sector Size. Possible values are: `512` and `4096`. Defaults to `4096`. Changing this forces a new resource to be created. + +~> **NOTE**: Setting logical sector size is supported only with `UltraSSD_LRS` disks. + * `os_type` - (Optional) Specify a value when the source of an `Import` 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 to copy `create_option` is `Copy` or the recovery point to restore when `create_option` is `Restore`