diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine.go b/builtin/providers/azurerm/resource_arm_virtual_machine.go index cbbe8d92a..c94a2286f 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine.go @@ -156,6 +156,12 @@ func resourceArmVirtualMachine() *schema.Resource { Type: schema.TypeString, Required: true, }, + + "disk_size_gb": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validateDiskSizeGB, + }, }, }, Set: resourceArmVirtualMachineStorageOsDiskHash, @@ -188,16 +194,9 @@ func resourceArmVirtualMachine() *schema.Resource { }, "disk_size_gb": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - value := v.(int) - if value < 1 || value > 1023 { - errors = append(errors, fmt.Errorf( - "The `disk_size_gb` can only be between 1 and 1023")) - } - return - }, + Type: schema.TypeInt, + Required: true, + ValidateFunc: validateDiskSizeGB, }, "lun": { @@ -429,6 +428,15 @@ func resourceArmVirtualMachine() *schema.Resource { } } +func validateDiskSizeGB(v interface{}, k string) (ws []string, errors []error) { + value := v.(int) + if value < 1 || value > 1023 { + errors = append(errors, fmt.Errorf( + "The `disk_size_gb` can only be between 1 and 1023")) + } + return +} + func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient) vmClient := client.vmClient @@ -924,6 +932,9 @@ func flattenAzureRmVirtualMachineOsDisk(disk *compute.OSDisk) []interface{} { result["vhd_uri"] = *disk.Vhd.URI result["create_option"] = disk.CreateOption result["caching"] = disk.Caching + if disk.DiskSizeGB != nil { + result["disk_size_gb"] = *disk.DiskSizeGB + } return []interface{}{result} } @@ -1258,5 +1269,10 @@ func expandAzureRmVirtualMachineOsDisk(d *schema.ResourceData) (*compute.OSDisk, osDisk.Caching = compute.CachingTypes(v) } + if v := disk["disk_size_gb"].(int); v != 0 { + diskSize := int32(v) + osDisk.DiskSizeGB = &diskSize + } + return osDisk, nil } diff --git a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go index 1bae80e6f..b080873e1 100644 --- a/builtin/providers/azurerm/resource_arm_virtual_machine_test.go +++ b/builtin/providers/azurerm/resource_arm_virtual_machine_test.go @@ -524,6 +524,7 @@ resource "azurerm_virtual_machine" "test" { vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" caching = "ReadWrite" create_option = "FromImage" + disk_size_gb = "45" } os_profile { diff --git a/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown b/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown index e959b9a0e..beb2b62c8 100644 --- a/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown +++ b/website/source/docs/providers/azurerm/r/virtual_machine.html.markdown @@ -249,6 +249,7 @@ For more information on the different example configurations, please check out t * `caching` - (Optional) Specifies the caching requirements. * `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 data disk in gigabytes. `storage_data_disk` supports the following: