From 9a90417f91f37793a1fdb74235552ea17853aead Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Wed, 18 Dec 2019 21:12:27 +0100 Subject: [PATCH] r/shared_image_version - support for the storage_account_type property (#5212) This PR incorporates and supersedes #4865 by making the storage_account_type field computed & removing the List assertions from the tests since it's a Set. Supersedes #4865 Fixes #4833 --- azurerm/data_source_shared_image_version.go | 9 +- .../data_source_shared_image_version_test.go | 1 + azurerm/resource_arm_shared_image_version.go | 11 ++ .../resource_arm_shared_image_version_test.go | 106 ++++++++++++++++++ .../docs/d/shared_image_version.html.markdown | 2 + .../docs/r/shared_image_version.html.markdown | 3 + 6 files changed, 131 insertions(+), 1 deletion(-) diff --git a/azurerm/data_source_shared_image_version.go b/azurerm/data_source_shared_image_version.go index 5e2f6d9e8e67..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{ @@ -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"] = string(v.StorageAccountType) + results = append(results, output) } } diff --git a/azurerm/data_source_shared_image_version_test.go b/azurerm/data_source_shared_image_version_test.go index 56af8676c853..7e7db2b303b4 100644 --- a/azurerm/data_source_shared_image_version_test.go +++ b/azurerm/data_source_shared_image_version_test.go @@ -37,6 +37,7 @@ 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"), ), }, }, diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/resource_arm_shared_image_version.go index f014942a3b76..9c9f902d1aa3 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/resource_arm_shared_image_version.go @@ -82,6 +82,13 @@ func resourceArmSharedImageVersion() *schema.Resource { Type: schema.TypeInt, Required: true, }, + + "storage_account_type": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, }, }, }, @@ -256,10 +263,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(storageAccountType), } results = append(results, output) } @@ -282,6 +291,8 @@ func flattenSharedImageVersionTargetRegions(input *[]compute.TargetRegion) []int output["regional_replica_count"] = int(*v.RegionalReplicaCount) } + output["storage_account_type"] = string(v.StorageAccountType) + results = append(results, output) } } diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/resource_arm_shared_image_version_test.go index 47063c23932d..b09851eee1bc 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/resource_arm_shared_image_version_test.go @@ -61,6 +61,89 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { }, }) } + +func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(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_LRS"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSharedImageVersionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + ), + }, + { + 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( + testCheckAzureRMSharedImageVersionExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), + resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -217,6 +300,29 @@ resource "azurerm_shared_image_version" "test" { } `, template) } + +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 + +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 = "%s" + } +} +`, template, storageAccountType) +} + func testAccAzureRMSharedImageVersion_requiresImport(rInt int, location, username, password, hostname string) string { return fmt.Sprintf(` %s 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: