Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to have 0 in disk_size_gb property of managed_disk #800

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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