From bee454fa0fc2d4a8ee8bffe817aa879780ac1ab3 Mon Sep 17 00:00:00 2001 From: Eugene Chuvyrov Date: Mon, 5 Feb 2018 17:16:42 -0800 Subject: [PATCH] Added an option to have 0 in disk_size_gb property of managed_disk --- azurerm/resource_arm_managed_disk.go | 5 ++- azurerm/resource_arm_managed_disk_test.go | 45 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_managed_disk.go b/azurerm/resource_arm_managed_disk.go index d531e5136ebb..a6c94137f644 100644 --- a/azurerm/resource_arm_managed_disk.go +++ b/azurerm/resource_arm_managed_disk.go @@ -86,6 +86,7 @@ func resourceArmManagedDisk() *schema.Resource { "disk_size_gb": { Type: schema.TypeInt, Optional: true, + Computed: true, ValidateFunc: validateDiskSizeGB, }, @@ -98,9 +99,9 @@ func resourceArmManagedDisk() *schema.Resource { func validateDiskSizeGB(v interface{}, k string) (ws []string, errors []error) { value := v.(int) - if value < 1 || value > 4095 { + if value < 0 || value > 4095 { errors = append(errors, fmt.Errorf( - "The `disk_size_gb` can only be between 1 and 4095")) + "The `disk_size_gb` can only be between 0 and 4095")) } return } diff --git a/azurerm/resource_arm_managed_disk_test.go b/azurerm/resource_arm_managed_disk_test.go index 40b03696da3c..955d096d99b4 100644 --- a/azurerm/resource_arm_managed_disk_test.go +++ b/azurerm/resource_arm_managed_disk_test.go @@ -30,6 +30,25 @@ func TestAccAzureRMManagedDisk_empty(t *testing.T) { }) } +func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) { + var d compute.Disk + ri := acctest.RandInt() + config := testAccAzureRMManagedDisk_zeroGbFromPlatformImage(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMManagedDiskDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true), + ), + }, + }, + }) +} + func TestAccAzureRMManagedDisk_import(t *testing.T) { var d compute.Disk var vm compute.VirtualMachine @@ -451,6 +470,32 @@ resource "azurerm_managed_disk" "test" { `, location, rInt, location, rInt) } +func testAccAzureRMManagedDisk_zeroGbFromPlatformImage(rInt int, location string) string { + return fmt.Sprintf(` +data "azurerm_platform_image" "test" { + location = "%s" + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} +resource "azurerm_managed_disk" "test" { + name = "acctestd-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + os_type = "Linux" + create_option = "FromImage" + disk_size_gb = "0" + image_reference_id = "${data.azurerm_platform_image.test.id}" + storage_account_type = "Standard_LRS" +} +`, location, rInt, location, rInt) +} + func testAccAzureRMManagedDisk_encryption(rInt int, rString string, location string) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {}