Skip to content

Commit

Permalink
Merge pull request #800 from echuvyrov/managed-disk-zero-size-gb
Browse files Browse the repository at this point in the history
Added an option to have 0 in disk_size_gb property of managed_disk
  • Loading branch information
tombuildsstuff authored Feb 8, 2018
2 parents 5922feb + bee454f commit dc7a4c2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
5 changes: 3 additions & 2 deletions azurerm/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func resourceArmManagedDisk() *schema.Resource {
"disk_size_gb": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validateDiskSizeGB,
},

Expand All @@ -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
}
Expand Down
45 changes: 45 additions & 0 deletions azurerm/resource_arm_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" {}
Expand Down

0 comments on commit dc7a4c2

Please sign in to comment.