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_virtual_machine - add support for write_accelerator_enabled to disks #964

Merged
merged 6 commits into from
Jun 1, 2018
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
36 changes: 31 additions & 5 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func resourceArmVirtualMachine() *schema.Resource {
Computed: true,
ValidateFunc: validateDiskSizeGB,
},

"write_accelerator_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -294,6 +300,12 @@ func resourceArmVirtualMachine() *schema.Resource {
Type: schema.TypeInt,
Required: true,
},

"write_accelerator_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand Down Expand Up @@ -990,6 +1002,10 @@ func flattenAzureRmVirtualMachineDataDisk(disks *[]compute.DataDisk, disksInfo [
}
l["lun"] = *disk.Lun

if v := disk.WriteAcceleratorEnabled; v != nil {
l["write_accelerator_enabled"] = *disk.WriteAcceleratorEnabled
}

flattenAzureRmVirtualMachineReviseDiskInfo(l, disksInfo[i])

result[i] = l
Expand Down Expand Up @@ -1099,6 +1115,10 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk, diskInfo *compute.
}
result["os_type"] = string(disk.OsType)

if v := disk.WriteAcceleratorEnabled; v != nil {
result["write_accelerator_enabled"] = *disk.WriteAcceleratorEnabled
}

flattenAzureRmVirtualMachineReviseDiskInfo(result, diskInfo)

return []interface{}{result}
Expand Down Expand Up @@ -1393,9 +1413,12 @@ func expandAzureRmVirtualMachineDataDisk(d *schema.ResourceData) ([]compute.Data
data_disk.Caching = compute.CachingTypes(v)
}

if v := config["disk_size_gb"]; v != nil {
diskSize := int32(config["disk_size_gb"].(int))
data_disk.DiskSizeGB = &diskSize
if v, ok := config["disk_size_gb"].(int); ok {
data_disk.DiskSizeGB = utils.Int32(int32(v))
}

if v, ok := config["write_accelerator_enabled"].(bool); ok {
data_disk.WriteAcceleratorEnabled = utils.Bool(v)
}

data_disks = append(data_disks, data_disk)
Expand Down Expand Up @@ -1542,8 +1565,11 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk,
}

if v := config["disk_size_gb"].(int); v != 0 {
diskSize := int32(v)
osDisk.DiskSizeGB = &diskSize
osDisk.DiskSizeGB = utils.Int32(int32(v))
}

if v, ok := config["write_accelerator_enabled"].(bool); ok {
osDisk.WriteAcceleratorEnabled = utils.Bool(v)
}

return osDisk, nil
Expand Down
247 changes: 246 additions & 1 deletion azurerm/resource_arm_virtual_machine_managed_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func TestAccAzureRMVirtualMachine_enableAnWithVM(t *testing.T) {
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachine_anWithVM(rInt, testLocation()),
Config: testAccAzureRMVirtualMachine_anWithVM(rInt, testAltLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
),
Expand All @@ -361,6 +361,83 @@ func TestAccAzureRMVirtualMachine_enableAnWithVM(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeOsWriteAcceleratorEnabled(t *testing.T) {
resourceName := "azurerm_virtual_machine.test"
rInt := acctest.RandInt()
var vm compute.VirtualMachine

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt, testAltLocation(), "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.write_accelerator_enabled", "true"),
),
},
{
Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt, testAltLocation(), "false"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.write_accelerator_enabled", "false"),
),
},
},
})
}

func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(t *testing.T) {
resourceName := "azurerm_virtual_machine.test"
rInt := acctest.RandInt()
var vm compute.VirtualMachine

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, testAltLocation(), "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "true"),
),
},
},
})
}

func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeWriteAcceleratorEnabled(t *testing.T) {
resourceName := "azurerm_virtual_machine.test"
rInt := acctest.RandInt()
var vm compute.VirtualMachine

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, testAltLocation(), "false"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "false"),
),
},
{
Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, testAltLocation(), "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists(resourceName, &vm),
resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "true"),
),
},
},
})
}

func TestAccAzureRMVirtualMachine_winRMCerts(t *testing.T) {
var vm compute.VirtualMachine
resourceName := "azurerm_virtual_machine.test"
Expand Down Expand Up @@ -437,6 +514,174 @@ func testCheckAndStopAzureRMVirtualMachine(vm *compute.VirtualMachine) resource.
}
}

func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt int, location, enabled string) 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"

delete_os_disk_on_termination = true

storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

storage_os_disk {
name = "osd-%d"
create_option = "FromImage"
caching = "None"
disk_size_gb = "50"
managed_disk_type = "Premium_LRS"
write_accelerator_enabled = %s
}

storage_data_disk {
name = "acctmd-%d"
create_option = "Empty"
disk_size_gb = "1"
managed_disk_type = "Standard_LRS"
lun = 0
}

os_profile {
computer_name = "hn%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}

os_profile_linux_config {
disable_password_authentication = false
}

tags {
environment = "Production"
cost-center = "Ops"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, enabled, rInt, rInt)
}

func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt int, location, enabled string) 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"

delete_os_disk_on_termination = true

storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}

storage_os_disk {
name = "osd-%d"
caching = "ReadWrite"
create_option = "FromImage"
disk_size_gb = "50"
managed_disk_type = "Standard_LRS"
}

storage_data_disk {
name = "acctmd-%d"
create_option = "Empty"
disk_size_gb = "1"
managed_disk_type = "Premium_LRS"
lun = 0
write_accelerator_enabled = %s
}

os_profile {
computer_name = "hn%d"
admin_username = "testadmin"
admin_password = "Password1234!"
}

os_profile_linux_config {
disable_password_authentication = false
}

tags {
environment = "Production"
cost-center = "Ops"
}
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled, rInt)
}

func testAccAzureRMVirtualMachine_winRMCerts(rString string, location string) string {
return fmt.Sprintf(`
variable "prefix" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ resource "azurerm_virtual_machine" "test" {
* `image_uri` - (Optional) Specifies the image_uri in the form publisherName:offer:skus:version. `image_uri` can also specify the [VHD uri](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-deploy-templates/#create-a-custom-vm-image) of a custom VM image to clone. When cloning a custom disk image the `os_type` documented below becomes required.
* `os_type` - (Optional) Specifies the operating system Type, valid values are windows, linux.
* `disk_size_gb` - (Optional) Specifies the size of the os disk in gigabytes.
* `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`.

`storage_data_disk` supports the following:

Expand All @@ -423,6 +424,7 @@ resource "azurerm_virtual_machine" "test" {
* `disk_size_gb` - (Required) Specifies the size of the data disk in gigabytes.
* `caching` - (Optional) Specifies the caching requirements.
* `lun` - (Required) Specifies the logical unit number of the data disk.
* `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`.

`os_profile` supports the following:

Expand Down