Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for StorageAccountType on azurerm_shared_image_version #4865

Closed
wants to merge 15 commits into from
Closed
7 changes: 7 additions & 0 deletions azurerm/data_source_shared_image_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = 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
10 changes: 10 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,12 @@ func resourceArmSharedImageVersion() *schema.Resource {
Type: schema.TypeInt,
Required: true,
},

"storage_account_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
Expand Down Expand Up @@ -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(storageAccountType),
}
results = append(results, output)
}
Expand All @@ -282,6 +290,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
108 changes: 108 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,91 @@ 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"),
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(
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"),
),
cwebbtw marked this conversation as resolved.
Show resolved Hide resolved
},
{
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 +302,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