Skip to content

Commit

Permalink
Update managed disk docs with correct size types, remove import tests…
Browse files Browse the repository at this point in the history
… & tidy tests
  • Loading branch information
katbyte committed Oct 19, 2018
1 parent 2b3b8b1 commit 5ff3997
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 89 deletions.
50 changes: 0 additions & 50 deletions azurerm/import_arm_managed_disk_test.go

This file was deleted.

4 changes: 3 additions & 1 deletion azurerm/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package azurerm

import (
"fmt"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"log"
"strings"

Expand All @@ -18,6 +19,7 @@ func resourceArmManagedDisk() *schema.Resource {
Read: resourceArmManagedDiskRead,
Update: resourceArmManagedDiskCreate,
Delete: resourceArmManagedDiskDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand All @@ -43,7 +45,7 @@ func resourceArmManagedDisk() *schema.Resource {
string(compute.PremiumLRS),
string(compute.StandardSSDLRS),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
},

"create_option": {
Expand Down
107 changes: 70 additions & 37 deletions azurerm/resource_arm_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,65 @@ import (
)

func TestAccAzureRMManagedDisk_empty(t *testing.T) {
var d compute.Disk
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
config := testAccAzureRMManagedDisk_empty(ri, testLocation())
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMManagedDisk_empty(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) {
var d compute.Disk
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
config := testAccAzureRMManagedDisk_zeroGbFromPlatformImage(ri, testLocation())
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMManagedDisk_zeroGbFromPlatformImage(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
},
})
}

func TestAccAzureRMManagedDisk_import(t *testing.T) {
var d compute.Disk
var vm compute.VirtualMachine
ri := acctest.RandInt()
resourceName := "azurerm_key_vault_secret.test"
location := testLocation()
vmConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location)
config := testAccAzureRMManagedDisk_import(ri, location)
ri := acctest.RandInt()
var vm compute.VirtualMachine
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
//need to create a vm and then delete it so we can use the vhd to test import
Config: vmConfig,
Config: testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location),
Destroy: false,
ExpectNonEmptyPlan: true,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -72,67 +79,67 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) {
),
},
{
Config: config,
Config: testAccAzureRMManagedDisk_import(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
},
})
}

func TestAccAzureRMManagedDisk_copy(t *testing.T) {
var d compute.Disk
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
config := testAccAzureRMManagedDisk_copy(ri, testLocation())
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMManagedDisk_copy(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
},
})
}

func TestAccAzureRMManagedDisk_fromPlatformImage(t *testing.T) {
var d compute.Disk
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
config := testAccAzureRMManagedDisk_platformImage(ri, testLocation())
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMManagedDisk_platformImage(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
},
})
}

func TestAccAzureRMManagedDisk_update(t *testing.T) {
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
var d compute.Disk

resourceName := "azurerm_managed_disk.test"
ri := acctest.RandInt()
preConfig := testAccAzureRMManagedDisk_empty(ri, testLocation())
postConfig := testAccAzureRMManagedDisk_empty_updated(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAzureRMManagedDisk_empty(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
Expand All @@ -143,7 +150,7 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) {
),
},
{
Config: postConfig,
Config: testAccAzureRMManagedDisk_empty_updated(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
Expand All @@ -157,19 +164,18 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) {
}

func TestAccAzureRMManagedDisk_encryption(t *testing.T) {
var d compute.Disk

resourceName := "azurerm_managed_disk.test"
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
rs := acctest.RandString(4)
preConfig := testAccAzureRMManagedDisk_encryption(ri, rs, testLocation())
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAzureRMManagedDisk_encryption(ri, rs, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
resource.TestCheckResourceAttr(resourceName, "encryption_settings.#", "1"),
Expand All @@ -187,8 +193,10 @@ func TestAccAzureRMManagedDisk_encryption(t *testing.T) {
}

func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) {
var d compute.Disk
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
var d compute.Disk

config := testAccAzureRMManagedDiskNonStandardCasing(ri, testLocation())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -198,7 +206,7 @@ func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists("azurerm_managed_disk.test", &d, true),
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
{
Expand All @@ -210,6 +218,31 @@ func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) {
})
}

func TestAccAzureRMManagedDisk_importEmpty_withZone(t *testing.T) {
resourceName := "azurerm_key_vault_secret.test"
ri := acctest.RandInt()
var d compute.Disk

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMManagedDisk_empty_withZone(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMManagedDiskExists(resourceName, &d, true),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMManagedDiskExists(name string, d *compute.Disk, shouldExist bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The following arguments are supported:
Changing this forces a new resource to be created.

* `storage_account_type` - (Required) The type of storage to use for the managed disk.
Allowable values are `Standard_LRS` or `Premium_LRS`.
Allowable values are `StandardLRS`, `PremiumLRS` or `StandardSSDLRS`.

* `create_option` - (Required) The method to use when creating the managed disk. Possible values include:
* `Import` - Import a VHD file in to the managed disk (VHD specified with `source_uri`).
Expand Down

0 comments on commit 5ff3997

Please sign in to comment.