From a0c025621cdf5fa75170ab9d98387fc7bd9a8ea6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 12 Nov 2019 23:21:30 +0000 Subject: [PATCH 01/14] CW Supporting storage_account_type for shared image version resource/data --- azurerm/data_source_shared_image_version.go | 7 +++++++ azurerm/resource_arm_shared_image_version.go | 10 ++++++++++ website/docs/d/shared_image_version.html.markdown | 2 ++ website/docs/r/shared_image_version.html.markdown | 3 +++ 4 files changed, 22 insertions(+) diff --git a/azurerm/data_source_shared_image_version.go b/azurerm/data_source_shared_image_version.go index 5e2f6d9e8e67..9c547f382fbd 100644 --- a/azurerm/data_source_shared_image_version.go +++ b/azurerm/data_source_shared_image_version.go @@ -64,6 +64,11 @@ func dataSourceArmSharedImageVersion() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + + "storage_account_type": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -144,6 +149,8 @@ func flattenSharedImageVersionDataSourceTargetRegions(input *[]compute.TargetReg output["regional_replica_count"] = int(*v.RegionalReplicaCount) } + output["storage_account_type"] = v.StorageAccountType + results = append(results, output) } } diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/resource_arm_shared_image_version.go index f014942a3b76..b87e381df5cb 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/resource_arm_shared_image_version.go @@ -82,6 +82,12 @@ func resourceArmSharedImageVersion() *schema.Resource { Type: schema.TypeInt, Required: true, }, + + "storage_account_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, }, }, @@ -256,10 +262,12 @@ func expandSharedImageVersionTargetRegions(d *schema.ResourceData) *[]compute.Ta name := input["name"].(string) regionalReplicaCount := input["regional_replica_count"].(int) + storageAccountType := input["storage_account_type"].(string) output := compute.TargetRegion{ Name: utils.String(name), RegionalReplicaCount: utils.Int32(int32(regionalReplicaCount)), + StorageAccountType: compute.StorageAccountType(string(storageAccountType)), } results = append(results, output) } @@ -282,6 +290,8 @@ func flattenSharedImageVersionTargetRegions(input *[]compute.TargetRegion) []int output["regional_replica_count"] = int(*v.RegionalReplicaCount) } + output["storage_account_type"] = v.StorageAccountType + results = append(results, output) } } diff --git a/website/docs/d/shared_image_version.html.markdown b/website/docs/d/shared_image_version.html.markdown index 55e6c7ff896f..860d7397c745 100644 --- a/website/docs/d/shared_image_version.html.markdown +++ b/website/docs/d/shared_image_version.html.markdown @@ -58,3 +58,5 @@ The `target_region` block exports the following: * `name` - The Azure Region in which this Image Version exists. * `regional_replica_count` - The number of replicas of the Image Version to be created per region. + +* `storage_account_type` - The storage account type for the image version. diff --git a/website/docs/r/shared_image_version.html.markdown b/website/docs/r/shared_image_version.html.markdown index d98a8d81927c..b6181ebc3c71 100644 --- a/website/docs/r/shared_image_version.html.markdown +++ b/website/docs/r/shared_image_version.html.markdown @@ -37,6 +37,7 @@ resource "azurerm_shared_image_version" "example" { target_region { name = "${data.azurerm_shared_image.existing.location}" regional_replica_count = "5" + storage_account_type = "Standard_LRS" } } ``` @@ -73,6 +74,8 @@ The `target_region` block exports the following: * `regional_replica_count` - (Required) The number of replicas of the Image Version to be created per region. +* `storage_account_type` - (Optional) The storage account type for the image version, which defaults to `Standard_LRS`. You can store all of your image version replicas in Zone Redundant Storage by specifying `Standard_ZRS`. + ## Attributes Reference The following attributes are exported: From a62da4ead56e80df5dd8afa60859b20129c524da Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 13 Nov 2019 12:28:14 +0000 Subject: [PATCH 02/14] CW Acceptance tests for storage_account_type --- .../data_source_shared_image_version_test.go | 24 +++++++++++++++++++ .../resource_arm_shared_image_version_test.go | 21 ++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/azurerm/data_source_shared_image_version_test.go b/azurerm/data_source_shared_image_version_test.go index 56af8676c853..e8a806c308e9 100644 --- a/azurerm/data_source_shared_image_version_test.go +++ b/azurerm/data_source_shared_image_version_test.go @@ -37,6 +37,16 @@ func TestAccDataSourceAzureRMSharedImageVersion_basic(t *testing.T) { resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), resource.TestCheckResourceAttrSet(dataSourceName, "managed_image_id"), resource.TestCheckResourceAttr(dataSourceName, "target_region.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "target_region.0.storage_account_type", "Standard_LRS"), + ), + }, + { + Config: testAccDataSourceSharedImageVersion_zrs(rInt, location, username, password, hostname), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(dataSourceName, "managed_image_id"), + resource.TestCheckResourceAttr(dataSourceName, "target_region.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "target_region.0.storage_account_type", "Standard_ZRS"), ), }, }, @@ -56,3 +66,17 @@ data "azurerm_shared_image_version" "test" { } `, template) } + +func testAccDataSourceSharedImageVersion_zrs(rInt int, location, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_imageVersionZrs(rInt, location, username, password, hostname) + return fmt.Sprintf(` +%s + +data "azurerm_shared_image_version" "test" { + name = "${azurerm_shared_image_version.test.name}" + gallery_name = "${azurerm_shared_image_version.test.gallery_name}" + image_name = "${azurerm_shared_image_version.test.image_name}" + resource_group_name = "${azurerm_shared_image_version.test.resource_group_name}" +} +`, template) +} diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index 47063c23932d..18b55db06171 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -217,6 +217,27 @@ resource "azurerm_shared_image_version" "test" { } `, template) } +func testAccAzureRMSharedImageVersion_imageVersionZrs(rInt int, location, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) + return fmt.Sprintf(` +%s + +resource "azurerm_shared_image_version" "test" { + name = "0.0.1" + gallery_name = "${azurerm_shared_image_gallery.test.name}" + image_name = "${azurerm_shared_image.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + managed_image_id = "${azurerm_image.test.id}" + + target_region { + name = "${azurerm_resource_group.test.location}" + regional_replica_count = 1 + storage_account_type = "Standard_ZRS" + } +} +`, template) +} func testAccAzureRMSharedImageVersion_requiresImport(rInt int, location, username, password, hostname string) string { return fmt.Sprintf(` %s From 8914195a950900ab24c82eea2dc5278a5f11e3b7 Mon Sep 17 00:00:00 2001 From: Christopher Date: Wed, 13 Nov 2019 13:16:59 +0000 Subject: [PATCH 03/14] CW Fix for travislint --- azurerm/resource_arm_shared_image_version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/resource_arm_shared_image_version.go index b87e381df5cb..fd513ae3f09f 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/resource_arm_shared_image_version.go @@ -267,7 +267,7 @@ func expandSharedImageVersionTargetRegions(d *schema.ResourceData) *[]compute.Ta output := compute.TargetRegion{ Name: utils.String(name), RegionalReplicaCount: utils.Int32(int32(regionalReplicaCount)), - StorageAccountType: compute.StorageAccountType(string(storageAccountType)), + StorageAccountType: compute.StorageAccountType(storageAccountType), } results = append(results, output) } From 083096881c76002830fb69f600364ddadcfb3660 Mon Sep 17 00:00:00 2001 From: Christopher Webb <31657038+cwebbtw@users.noreply.github.com> Date: Thu, 14 Nov 2019 12:39:50 +0000 Subject: [PATCH 04/14] Update azurerm/resource_arm_shared_image_version.go Accepting recommended change. Co-Authored-By: Tom Harvey --- azurerm/resource_arm_shared_image_version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/resource_arm_shared_image_version.go index fd513ae3f09f..96965026f0d9 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/resource_arm_shared_image_version.go @@ -290,7 +290,7 @@ func flattenSharedImageVersionTargetRegions(input *[]compute.TargetRegion) []int output["regional_replica_count"] = int(*v.RegionalReplicaCount) } - output["storage_account_type"] = v.StorageAccountType + output["storage_account_type"] = string(v.StorageAccountType) results = append(results, output) } From 23bcf64a8f906062bb534ab24065869f6f1b82f2 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Nov 2019 13:36:37 +0000 Subject: [PATCH 05/14] CW Adding test step for standard ZRS storage account type --- .../resource_arm_shared_image_version_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index 18b55db06171..a90f7a2210e4 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -44,6 +44,23 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), ), }, + { + Config: testAccAzureRMSharedImageVersion_imageVersion(ri, testLocation(), userName, password, hostName), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSharedImageVersionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + ), + }, + { + Config: testAccAzureRMSharedImageVersion_imageVersionZrs(ri, testLocation(), userName, password, hostName), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSharedImageVersionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), + ), + }, { Config: testAccAzureRMSharedImageVersion_imageVersionUpdated(ri, testLocation(), testAltLocation(), userName, password, hostName), Check: resource.ComposeTestCheckFunc( From 736682adc87ad5d8d19bcc168fb742dc82d18464 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Nov 2019 13:40:19 +0000 Subject: [PATCH 06/14] CW Removing duplicate test --- azurerm/resource_arm_shared_image_version_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index a90f7a2210e4..85b4c3e5f7ba 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -44,14 +44,6 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), ), }, - { - Config: testAccAzureRMSharedImageVersion_imageVersion(ri, testLocation(), userName, password, hostName), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), - ), - }, { Config: testAccAzureRMSharedImageVersion_imageVersionZrs(ri, testLocation(), userName, password, hostName), Check: resource.ComposeTestCheckFunc( From 01d7b79f877595be1f2d1c69ddf0b595cf177b03 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Nov 2019 13:52:10 +0000 Subject: [PATCH 07/14] CW Isolating storage account type verification into new test case --- .../resource_arm_shared_image_version_test.go | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index 85b4c3e5f7ba..e60d2ffd527b 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -45,21 +45,63 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionZrs(ri, testLocation(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersionUpdated(ri, testLocation(), testAltLocation(), userName, password, hostName), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSharedImageVersionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "2"), + resource.TestCheckResourceAttr(resourceName, "name", "1234567890.1234567890.1234567890"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { + resourceName := "azurerm_shared_image_version.test" + + ri := tf.AccRandTimeInt() + resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + userName := "testadmin" + password := "Password1234!" + hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + sshPort := "22" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMSharedImageVersionDestroy, + Steps: []resource.TestStep{ + { + // need to create a vm and then reference it in the image creation + Config: testAccAzureRMSharedImageVersion_setup(ri, testLocation(), userName, password, hostName), + Destroy: false, + Check: resource.ComposeTestCheckFunc( + testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, testLocation()), + ), + }, + { + Config: testAccAzureRMSharedImageVersion_imageVersionLrs(ri, testLocation(), userName, password, hostName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), - resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), + resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_LRS"), ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionUpdated(ri, testLocation(), testAltLocation(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersionZrs(ri, testLocation(), userName, password, hostName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "2"), - resource.TestCheckResourceAttr(resourceName, "name", "1234567890.1234567890.1234567890"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), ), }, { @@ -70,6 +112,7 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { }, }) } + func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -226,6 +269,28 @@ resource "azurerm_shared_image_version" "test" { } `, template) } + +func testAccAzureRMSharedImageVersion_imageVersionLrs(rInt int, location, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) + return fmt.Sprintf(` +%s + +resource "azurerm_shared_image_version" "test" { + name = "0.0.1" + gallery_name = "${azurerm_shared_image_gallery.test.name}" + image_name = "${azurerm_shared_image.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + managed_image_id = "${azurerm_image.test.id}" + + target_region { + name = "${azurerm_resource_group.test.location}" + regional_replica_count = 1 + storage_account_type = "Standard_LRS" + } +} +`, template) +} func testAccAzureRMSharedImageVersion_imageVersionZrs(rInt int, location, username, password, hostname string) string { template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) return fmt.Sprintf(` From 29dccc2680ba74433123baf5c3c923898ee46510 Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Nov 2019 13:58:57 +0000 Subject: [PATCH 08/14] CW Refactor to reduce duplicate code (DRY) --- .../data_source_shared_image_version_test.go | 2 +- .../resource_arm_shared_image_version_test.go | 28 +++---------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/azurerm/data_source_shared_image_version_test.go b/azurerm/data_source_shared_image_version_test.go index e8a806c308e9..38340e7be2ef 100644 --- a/azurerm/data_source_shared_image_version_test.go +++ b/azurerm/data_source_shared_image_version_test.go @@ -68,7 +68,7 @@ data "azurerm_shared_image_version" "test" { } func testAccDataSourceSharedImageVersion_zrs(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_imageVersionZrs(rInt, location, username, password, hostname) + template := testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(rInt, location, username, password, hostname, "Standard_ZRS") return fmt.Sprintf(` %s diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index e60d2ffd527b..5f0c9817281b 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -87,7 +87,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionLrs(ri, testLocation(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(ri, testLocation(), userName, password, hostName, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), @@ -96,7 +96,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionZrs(ri, testLocation(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(ri, testLocation(), userName, password, hostName, "Standard_ZRS"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), @@ -270,7 +270,7 @@ resource "azurerm_shared_image_version" "test" { `, template) } -func testAccAzureRMSharedImageVersion_imageVersionLrs(rInt int, location, username, password, hostname string) string { +func testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(rInt int, location, username, password, hostname string, storageAccountType string) string { template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) return fmt.Sprintf(` %s @@ -286,32 +286,12 @@ resource "azurerm_shared_image_version" "test" { target_region { name = "${azurerm_resource_group.test.location}" regional_replica_count = 1 - storage_account_type = "Standard_LRS" + storage_account_type = "%s" } } `, template) } -func testAccAzureRMSharedImageVersion_imageVersionZrs(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) - return fmt.Sprintf(` -%s - -resource "azurerm_shared_image_version" "test" { - name = "0.0.1" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - image_name = "${azurerm_shared_image.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - managed_image_id = "${azurerm_image.test.id}" - target_region { - name = "${azurerm_resource_group.test.location}" - regional_replica_count = 1 - storage_account_type = "Standard_ZRS" - } -} -`, template) -} func testAccAzureRMSharedImageVersion_requiresImport(rInt int, location, username, password, hostname string) string { return fmt.Sprintf(` %s From e48c6e6c0c6b76256607d6a453e00e0a81fe763b Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 14 Nov 2019 17:32:04 +0000 Subject: [PATCH 09/14] CW Adding arguments --- azurerm/resource_arm_shared_image_version_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index 5f0c9817281b..ab94256a087a 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -289,7 +289,7 @@ resource "azurerm_shared_image_version" "test" { storage_account_type = "%s" } } -`, template) +`, template, storageAccountType) } func testAccAzureRMSharedImageVersion_requiresImport(rInt int, location, username, password, hostname string) string { From 5ea43e09bf776da85856034809ed98f08fd61839 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 18 Nov 2019 13:42:04 +0000 Subject: [PATCH 10/14] CW Splitting LRS/ZRS tests --- .../resource_arm_shared_image_version_test.go | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index ab94256a087a..c1885ce3fe4e 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -62,7 +62,7 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { }) } -func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { +func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { resourceName := "azurerm_shared_image_version.test" ri := tf.AccRandTimeInt() @@ -95,6 +95,39 @@ func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_LRS"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { + resourceName := "azurerm_shared_image_version.test" + + ri := tf.AccRandTimeInt() + resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + userName := "testadmin" + password := "Password1234!" + hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + sshPort := "22" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMSharedImageVersionDestroy, + Steps: []resource.TestStep{ + { + // need to create a vm and then reference it in the image creation + Config: testAccAzureRMSharedImageVersion_setup(ri, testLocation(), userName, password, hostName), + Destroy: false, + Check: resource.ComposeTestCheckFunc( + testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, testLocation()), + ), + }, { Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(ri, testLocation(), userName, password, hostName, "Standard_ZRS"), Check: resource.ComposeTestCheckFunc( @@ -103,7 +136,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountType(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), ), - }, + }, { ResourceName: resourceName, ImportState: true, From 03456606211eabc4b303ae18c110cf04783ff68d Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 18 Nov 2019 14:00:10 +0000 Subject: [PATCH 11/14] CW Removing superfluous test step from data source --- .../data_source_shared_image_version_test.go | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/azurerm/data_source_shared_image_version_test.go b/azurerm/data_source_shared_image_version_test.go index 38340e7be2ef..7e7db2b303b4 100644 --- a/azurerm/data_source_shared_image_version_test.go +++ b/azurerm/data_source_shared_image_version_test.go @@ -40,15 +40,6 @@ func TestAccDataSourceAzureRMSharedImageVersion_basic(t *testing.T) { resource.TestCheckResourceAttr(dataSourceName, "target_region.0.storage_account_type", "Standard_LRS"), ), }, - { - Config: testAccDataSourceSharedImageVersion_zrs(rInt, location, username, password, hostname), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(dataSourceName, "managed_image_id"), - resource.TestCheckResourceAttr(dataSourceName, "target_region.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "target_region.0.storage_account_type", "Standard_ZRS"), - ), - }, }, }) } @@ -66,17 +57,3 @@ data "azurerm_shared_image_version" "test" { } `, template) } - -func testAccDataSourceSharedImageVersion_zrs(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(rInt, location, username, password, hostname, "Standard_ZRS") - return fmt.Sprintf(` -%s - -data "azurerm_shared_image_version" "test" { - name = "${azurerm_shared_image_version.test.name}" - gallery_name = "${azurerm_shared_image_version.test.gallery_name}" - image_name = "${azurerm_shared_image_version.test.image_name}" - resource_group_name = "${azurerm_shared_image_version.test.resource_group_name}" -} -`, template) -} From a57554b2310f17fb0b7783b5b2dd694fa3051d17 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 19 Nov 2019 17:35:19 +0000 Subject: [PATCH 12/14] CW Linting --- azurerm/resource_arm_shared_image_version_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index c1885ce3fe4e..e264d3ee5337 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -136,7 +136,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), ), - }, + }, { ResourceName: resourceName, ImportState: true, From 24340ae6277e3b2f14b3054845c947fa9cbe14fd Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 18 Dec 2019 17:36:06 +0100 Subject: [PATCH 13/14] r/shared_image_version: fixing the tests --- azurerm/resource_arm_shared_image_version.go | 1 + azurerm/resource_arm_shared_image_version_test.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/resource_arm_shared_image_version.go index 96965026f0d9..9c9f902d1aa3 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/resource_arm_shared_image_version.go @@ -86,6 +86,7 @@ func resourceArmSharedImageVersion() *schema.Resource { "storage_account_type": { Type: schema.TypeString, Optional: true, + Computed: true, ForceNew: true, }, }, diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index e264d3ee5337..b09851eee1bc 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -92,7 +92,6 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), - resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_LRS"), ), }, { @@ -134,7 +133,6 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { testCheckAzureRMSharedImageVersionExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), - resource.TestCheckResourceAttr(resourceName, "target_region.0.storage_account_type", "Standard_ZRS"), ), }, { From 1aae5f679d255096b6d803971c401ee841064e05 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 18 Dec 2019 17:37:54 +0100 Subject: [PATCH 14/14] d/shared_image_version: making `target_region` a list since this is a data source --- azurerm/data_source_shared_image_version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/data_source_shared_image_version.go b/azurerm/data_source_shared_image_version.go index 9c547f382fbd..2facd71b39a4 100644 --- a/azurerm/data_source_shared_image_version.go +++ b/azurerm/data_source_shared_image_version.go @@ -51,7 +51,7 @@ func dataSourceArmSharedImageVersion() *schema.Resource { }, "target_region": { - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -149,7 +149,7 @@ func flattenSharedImageVersionDataSourceTargetRegions(input *[]compute.TargetReg output["regional_replica_count"] = int(*v.RegionalReplicaCount) } - output["storage_account_type"] = v.StorageAccountType + output["storage_account_type"] = string(v.StorageAccountType) results = append(results, output) }