Skip to content

Commit

Permalink
VM Data Disk Attachment: support for setting Write Accelerator Enabled (
Browse files Browse the repository at this point in the history
#1473)

```
acctests azurerm TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator
=== RUN   TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator
--- PASS: TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator (1068.82s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	1068.861s
```
  • Loading branch information
tombuildsstuff authored Jul 2, 2018
1 parent 7e85903 commit 9863a1c
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
9 changes: 9 additions & 0 deletions azurerm/resource_arm_virtual_machine_data_disk_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func resourceArmVirtualMachineDataDiskAttachment() *schema.Resource {
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"write_accelerator_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand Down Expand Up @@ -109,6 +115,7 @@ func resourceArmVirtualMachineDataDiskAttachmentCreateUpdate(d *schema.ResourceD
lun := int32(d.Get("lun").(int))
caching := d.Get("caching").(string)
createOption := compute.DiskCreateOptionTypes(d.Get("create_option").(string))
writeAcceleratorEnabled := d.Get("write_accelerator_enabled").(bool)

expandedDisk := compute.DataDisk{
Name: utils.String(name),
Expand All @@ -119,6 +126,7 @@ func resourceArmVirtualMachineDataDiskAttachmentCreateUpdate(d *schema.ResourceD
ID: utils.String(managedDiskId),
StorageAccountType: managedDisk.Sku.Name,
},
WriteAcceleratorEnabled: utils.Bool(writeAcceleratorEnabled),
}

disks := *virtualMachine.StorageProfile.DataDisks
Expand Down Expand Up @@ -205,6 +213,7 @@ func resourceArmVirtualMachineDataDiskAttachmentRead(d *schema.ResourceData, met
d.Set("virtual_machine_id", virtualMachine.ID)
d.Set("caching", string(disk.Caching))
d.Set("create_option", string(disk.CreateOption))
d.Set("write_accelerator_enabled", disk.WriteAcceleratorEnabled)

if managedDisk := disk.ManagedDisk; managedDisk != nil {
d.Set("managed_disk_id", managedDisk.ID)
Expand Down
119 changes: 119 additions & 0 deletions azurerm/resource_arm_virtual_machine_data_disk_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingCaching(t *testing.T
})
}

func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator(t *testing.T) {
resourceName := "azurerm_virtual_machine_data_disk_attachment.test"
ri := acctest.RandInt()
location := testAltLocation()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "false"),
),
},
{
Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "true"),
),
},
{
Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "false"),
),
},
},
})
}

func testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -266,6 +300,91 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" {
`, template)
}

func testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(rInt int, location string, enabled bool) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_network_interface" "test" {
name = "acctni-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}
resource "azurerm_virtual_machine" "test" {
name = "acctvm-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
network_interface_ids = ["${azurerm_network_interface.test.id}"]
vm_size = "Standard_M64s"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
os_profile {
computer_name = "hn%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
resource "azurerm_managed_disk" "test" {
name = "%d-disk1"
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 = 10
}
resource "azurerm_virtual_machine_data_disk_attachment" "test" {
managed_disk_id = "${azurerm_managed_disk.test.id}"
virtual_machine_id = "${azurerm_virtual_machine.test.id}"
lun = "0"
caching = "None"
write_accelerator_enabled = "%t"
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled)
}

func testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ The following arguments are supported:

* `create_option` - (Optional) The Create Option of the Data Disk, such as `Empty` or `Attach`. Defaults to `Attach`. Changing this forces a new resource to be created.

* `write_accelerator_enabled` - (Optional) Specifies if Write Accelerator is enabled on the disk. This can only be enabled on `Premium_LRS` managed disks with no caching and [M-Series VMs](https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/how-to-enable-write-accelerator). Defaults to `false`.

## Attributes Reference

The following attributes are exported:
Expand Down

0 comments on commit 9863a1c

Please sign in to comment.