From d265a6fee3a598cdb7318279cf38876c44fec4b7 Mon Sep 17 00:00:00 2001 From: Jonathan Rudenberg Date: Tue, 25 Oct 2016 12:54:55 -0400 Subject: [PATCH] provider/azurerm: Add disk_size_gb param to VM storage_os_disk (#9200) TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMVirtualMachine_basicLinuxMachine -timeout 120m === RUN TestAccAzureRMVirtualMachine_basicLinuxMachine --- PASS: TestAccAzureRMVirtualMachine_basicLinuxMachine (540.83s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 540.841s TF_ACC=1 go test ./builtin/providers/azurerm -v -run=TestAccAzureRMVirtualMachine_withDataDisk -timeout 120m === RUN TestAccAzureRMVirtualMachine_withDataDisk --- PASS: TestAccAzureRMVirtualMachine_withDataDisk (431.19s) PASS ok github.com/hashicorp/terraform/builtin/providers/azurerm 431.203s --- .../azurerm/resource_arm_virtual_machine.go | 36 +++++++++++++------ .../resource_arm_virtual_machine_test.go | 1 + .../azurerm/r/virtual_machine.html.markdown | 1 + 3 files changed, 28 insertions(+), 10 deletions(-) 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: