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

r/azurerm_managed_disk: Add support for logical_sector_size property #13637

Merged
merged 1 commit into from
Oct 6, 2021
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
22 changes: 20 additions & 2 deletions internal/services/compute/managed_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
41 changes: 41 additions & 0 deletions internal/services/compute/managed_disk_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/3.0-overview.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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).
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```
4 changes: 4 additions & 0 deletions website/docs/r/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down