Skip to content

Commit

Permalink
r/shared_image_version - support for the storage_account_type property (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
tombuildsstuff authored and katbyte committed Dec 18, 2019
1 parent 5480a12 commit 9a90417
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
9 changes: 8 additions & 1 deletion azurerm/data_source_shared_image_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -64,6 +64,11 @@ func dataSourceArmSharedImageVersion() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},

"storage_account_type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions azurerm/data_source_shared_image_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
11 changes: 11 additions & 0 deletions azurerm/resource_arm_shared_image_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
}
Expand Down
106 changes: 106 additions & 0 deletions azurerm/resource_arm_shared_image_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/shared_image_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions website/docs/r/shared_image_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9a90417

Please sign in to comment.