From 3359cdee83703420c56de7470910201699445708 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 19 Oct 2018 15:36:52 -0700 Subject: [PATCH] Update managed disk docs with correct size types, remove import tests & tidy tests --- azurerm/import_arm_managed_disk_test.go | 50 ---------- azurerm/resource_arm_managed_disk.go | 4 +- azurerm/resource_arm_managed_disk_test.go | 107 ++++++++++++++-------- website/docs/r/managed_disk.html.markdown | 2 +- 4 files changed, 74 insertions(+), 89 deletions(-) delete mode 100644 azurerm/import_arm_managed_disk_test.go diff --git a/azurerm/import_arm_managed_disk_test.go b/azurerm/import_arm_managed_disk_test.go deleted file mode 100644 index 1a94e04402d7..000000000000 --- a/azurerm/import_arm_managed_disk_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package azurerm - -import ( - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccAzureRMManagedDisk_importEmpty(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMManagedDisk_empty(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMManagedDiskDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - { - ResourceName: "azurerm_managed_disk.test", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMManagedDisk_importEmpty_withZone(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMManagedDisk_empty_withZone(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMManagedDiskDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - { - ResourceName: "azurerm_managed_disk.test", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} diff --git a/azurerm/resource_arm_managed_disk.go b/azurerm/resource_arm_managed_disk.go index 481a24f3a891..ca9b46fa1b2c 100644 --- a/azurerm/resource_arm_managed_disk.go +++ b/azurerm/resource_arm_managed_disk.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "log" "strings" @@ -18,6 +19,7 @@ func resourceArmManagedDisk() *schema.Resource { Read: resourceArmManagedDiskRead, Update: resourceArmManagedDiskCreate, Delete: resourceArmManagedDiskDelete, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -43,7 +45,7 @@ func resourceArmManagedDisk() *schema.Resource { string(compute.PremiumLRS), string(compute.StandardSSDLRS), }, true), - DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + DiffSuppressFunc: suppress.CaseDifference, }, "create_option": { diff --git a/azurerm/resource_arm_managed_disk_test.go b/azurerm/resource_arm_managed_disk_test.go index 091f45ded2f9..82e3d9d21e6e 100644 --- a/azurerm/resource_arm_managed_disk_test.go +++ b/azurerm/resource_arm_managed_disk_test.go @@ -12,37 +12,44 @@ 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), ), }, }, @@ -50,12 +57,12 @@ func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) { } 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, @@ -63,7 +70,7 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { 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( @@ -72,9 +79,9 @@ 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), ), }, }, @@ -82,18 +89,19 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { } 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), ), }, }, @@ -101,18 +109,19 @@ func TestAccAzureRMManagedDisk_copy(t *testing.T) { } 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), ), }, }, @@ -120,19 +129,17 @@ func TestAccAzureRMManagedDisk_fromPlatformImage(t *testing.T) { } 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"), @@ -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"), @@ -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"), @@ -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) }, @@ -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), ), }, { @@ -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] diff --git a/website/docs/r/managed_disk.html.markdown b/website/docs/r/managed_disk.html.markdown index 3290feb9c48b..e606ecff6cbf 100644 --- a/website/docs/r/managed_disk.html.markdown +++ b/website/docs/r/managed_disk.html.markdown @@ -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`).