Skip to content

Commit

Permalink
azurerm_virtual_machine: add support for Ultra SSD's (#3860)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkey1000 authored and katbyte committed Sep 1, 2019
1 parent 2c52f46 commit 14dc093
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
48 changes: 48 additions & 0 deletions azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func resourceArmVirtualMachine() *schema.Resource {
string(compute.StorageAccountTypesPremiumLRS),
string(compute.StorageAccountTypesStandardLRS),
string(compute.StorageAccountTypesStandardSSDLRS),
string(compute.StorageAccountTypesUltraSSDLRS),
}, true),
},

Expand Down Expand Up @@ -362,6 +363,21 @@ func resourceArmVirtualMachine() *schema.Resource {
},
},

"additional_capabilities": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ultra_ssd_enabled": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
},
},
},

"os_profile": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -635,6 +651,9 @@ func resourceArmVirtualMachineCreateUpdate(d *schema.ResourceData, meta interfac
properties.DiagnosticsProfile = diagnosticsProfile
}
}
if _, ok := d.GetOk("additional_capabilities"); ok {
properties.AdditionalCapabilities = expandAzureRmVirtualMachineAdditionalCapabilities(d)
}

if _, ok := d.GetOk("os_profile"); ok {
osProfile, err2 := expandAzureRmVirtualMachineOsProfile(d)
Expand Down Expand Up @@ -816,6 +835,9 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error setting `boot_diagnostics`: %#v", err)
}
}
if err := d.Set("additional_capabilities", flattenAzureRmVirtualMachineAdditionalCapabilities(props.AdditionalCapabilities)); err != nil {
return fmt.Errorf("Error setting `additional_capabilities`: %#v", err)
}

if profile := props.NetworkProfile; profile != nil {
if err := d.Set("network_interface_ids", flattenAzureRmVirtualMachineNetworkInterfaces(profile)); err != nil {
Expand Down Expand Up @@ -1094,6 +1116,18 @@ func flattenAzureRmVirtualMachineDiagnosticsProfile(profile *compute.BootDiagnos
return []interface{}{result}
}

func flattenAzureRmVirtualMachineAdditionalCapabilities(profile *compute.AdditionalCapabilities) []interface{} {
if profile == nil {
return []interface{}{}
}

result := make(map[string]interface{})
if v := profile.UltraSSDEnabled; v != nil {
result["ultra_ssd_enabled"] = *v
}
return []interface{}{result}
}

func flattenAzureRmVirtualMachineNetworkInterfaces(profile *compute.NetworkProfile) []interface{} {
result := make([]interface{}, 0)
for _, nic := range *profile.NetworkInterfaces {
Expand Down Expand Up @@ -1639,6 +1673,20 @@ func expandAzureRmVirtualMachineDiagnosticsProfile(d *schema.ResourceData) *comp
return nil
}

func expandAzureRmVirtualMachineAdditionalCapabilities(d *schema.ResourceData) *compute.AdditionalCapabilities {
additionalCapabilities := d.Get("additional_capabilities").([]interface{})
if len(additionalCapabilities) == 0 {
return nil
}

additionalCapability := additionalCapabilities[0].(map[string]interface{})
capability := &compute.AdditionalCapabilities{
UltraSSDEnabled: utils.Bool(additionalCapability["ultra_ssd_enabled"].(bool)),
}

return capability
}

func expandAzureRmVirtualMachineImageReference(d *schema.ResourceData) (*compute.ImageReference, error) {
storageImageRefs := d.Get("storage_image_reference").(*schema.Set).List()

Expand Down
104 changes: 104 additions & 0 deletions azurerm/resource_arm_virtual_machine_managed_disks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,27 @@ func TestAccAzureRMVirtualMachine_importBasic_withZone(t *testing.T) {
})
}

// this test requires eastus2 location and availability zone 1
// might be worth creating a `azurerm_compute_zones` resource to get the zones to use?
func TestAccAzureRMVirtualMachine_ultraSSD(t *testing.T) {
var vm compute.VirtualMachine
ri := tf.AccRandTimeInt()
config := testAccAzureRMVirtualMachine_ultraSSD(ri, testAltLocation())
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
),
},
},
})
}

func testCheckAndStopAzureRMVirtualMachine(vm *compute.VirtualMachine) resource.TestCheckFunc {
return func(s *terraform.State) error {
vmID, err := azure.ParseAzureResourceID(*vm.ID)
Expand Down Expand Up @@ -2551,3 +2572,86 @@ resource "azurerm_virtual_machine" "test" {
}
`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachine_ultraSSD(rInt int, location 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/28"]
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.0.0/29"
}
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_D2S_V3"
zones = ["1"]
additional_capabilities {
ultra_ssd_enabled = true
}
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk"
caching = "ReadWrite"
create_option = "FromImage"
os_type = "linux"
managed_disk_type = "Premium_LRS"
disk_size_gb = "64"
}
storage_data_disk {
name = "mydatadisk1"
caching = "None"
create_option = "Empty"
managed_disk_type = "UltraSSD_LRS"
disk_size_gb = "64"
lun = 1
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
`, rInt, location, rInt, rInt, rInt, rInt)
}
14 changes: 13 additions & 1 deletion website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ The following arguments are supported:

* `boot_diagnostics` - (Optional) A `boot_diagnostics` block.

* `additional_capabilities` - (Optional) A `additional_capabilities` block.

* `delete_os_disk_on_termination` - (Optional) Should the OS Disk (either the Managed Disk / VHD Blob) be deleted when the Virtual Machine is destroyed? Defaults to `false`.

* `delete_data_disks_on_termination` - (Optional) Should the Data Disks (either the Managed Disks / VHD Blobs) be deleted when the Virtual Machine is destroyed? Defaults to `false`.
Expand Down Expand Up @@ -172,6 +174,14 @@ A `boot_diagnostics` block supports the following:

---

A `additional_capabilities` block supports the following:

* `ultra_ssd_enabled` - (Required) Should Ultra SSD disk be enabled for this Virtual Machine?

-> **Note**: Azure Ultra Disk Storage is currently in preview and are not available to subscriptions that have not [requested](https://aka.ms/UltraSSDPreviewSignUp) onboarding to `Azure Ultra Disk Storage` preview. `Azure Ultra Disk Storage` is only available in `East US 2`, `North Europe`, and `Southeast Asia` regions. For more information see the `Azure Ultra Disk Storage` [product documentation](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-enable-ultra-ssd), [product blog](https://azure.microsoft.com/en-us/blog/announcing-the-general-availability-of-azure-ultra-disk-storage/) and [FAQ](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq-for-disks#ultra-disks).

---

A `identity` block supports the following:

* `type` - (Required) The Managed Service Identity Type of this Virtual Machine. Possible values are `SystemAssigned` (where Azure will generate a Service Principal for you), `UserAssigned` (where you can specify the Service Principal ID's) to be used by this Virtual Machine using the `identity_ids` field, and `SystemAssigned, UserAssigned` which assigns both a system managed identity as well as the specified user assigned identities.
Expand Down Expand Up @@ -299,7 +309,9 @@ A `storage_data_disk` block supports the following:

The following properties apply when using Managed Disks:

* `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Possible values are either `Standard_LRS`, `StandardSSD_LRS` or `Premium_LRS`.
* `managed_disk_type` - (Optional) Specifies the type of managed disk to create. Possible values are either `Standard_LRS`, `StandardSSD_LRS`, `Premium_LRS` or `UltraSSD_LRS`.

-> **Note**: `managed_disk_type` of type `UltraSSD_LRS` is currently in preview and are not available to subscriptions that have not [requested](https://aka.ms/UltraSSDPreviewSignUp) onboarding to `Azure Ultra Disk Storage` preview. `Azure Ultra Disk Storage` is only available in `East US 2`, `North Europe`, and `Southeast Asia` regions. For more information see the `Azure Ultra Disk Storage` [product documentation](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disks-enable-ultra-ssd), [product blog](https://azure.microsoft.com/en-us/blog/announcing-the-general-availability-of-azure-ultra-disk-storage/) and [FAQ](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq-for-disks#ultra-disks). You must also set `additional_capabilities.ultra_ssd_enabled` to `true`.

* `managed_disk_id` - (Optional) Specifies the ID of an Existing Managed Disk which should be attached to this Virtual Machine. When this field is set `create_option` must be set to `Attach`.

Expand Down

0 comments on commit 14dc093

Please sign in to comment.