-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Image] zone resilient property addition #3100
Changes from 4 commits
1153a1d
b291f50
79f6b42
27e5dbf
c0d06e9
a9ae39f
98c280e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,13 @@ func resourceArmImage() *schema.Resource { | |
|
||
"resource_group_name": resourceGroupNameSchema(), | ||
|
||
"zone_resilient": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we also Set this in the state here using the object returned from the API? https://github.com/terraform-providers/terraform-provider-azurerm/pull/3100/files#diff-95b4abb1c5040a8fd4f3c3674821b7b6R292 |
||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
ForceNew: true, | ||
}, | ||
|
||
"source_virtual_machine_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -166,6 +173,7 @@ func resourceArmImageCreateUpdate(d *schema.ResourceData, meta interface{}) erro | |
|
||
name := d.Get("name").(string) | ||
resGroup := d.Get("resource_group_name").(string) | ||
zoneResilient := d.Get("zone_resilient").(bool) | ||
|
||
if requireResourcesToBeImported && d.IsNewResource() { | ||
existing, err := client.Get(ctx, resGroup, name, "") | ||
|
@@ -196,8 +204,9 @@ func resourceArmImageCreateUpdate(d *schema.ResourceData, meta interface{}) erro | |
} | ||
|
||
storageProfile := compute.ImageStorageProfile{ | ||
OsDisk: osDisk, | ||
DataDisks: &dataDisks, | ||
OsDisk: osDisk, | ||
DataDisks: &dataDisks, | ||
ZoneResilient: utils.Bool(zoneResilient), | ||
} | ||
|
||
sourceVM := compute.SubResource{} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,52 @@ func TestAccAzureRMImage_standaloneImage(t *testing.T) { | |
hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) | ||
sshPort := "22" | ||
location := testLocation() | ||
preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location) | ||
postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location) | ||
preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "LRS") | ||
postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "LRS") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMImageDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
//need to create a vm and then reference it in the image creation | ||
Config: preConfig, | ||
Destroy: false, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), | ||
testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), | ||
), | ||
}, | ||
{ | ||
Config: postConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMImageExists("azurerm_image.test", true), | ||
), | ||
}, | ||
{ | ||
ResourceName: "azurerm_image.test", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAzureRMImage_standaloneImageZoneRedundant(t *testing.T) { | ||
ri := tf.AccRandTimeInt() | ||
resourceGroup := fmt.Sprintf("acctestRG-%d", ri) | ||
userName := "testadmin" | ||
password := "Password1234!" | ||
hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) | ||
sshPort := "22" | ||
location := testLocation() | ||
preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "ZRS") | ||
postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "ZRS") | ||
|
||
if !supportsZRS(location) { | ||
t.Skip(fmt.Sprintf("Integration test skipped because location '%s' does not support zone-redundant storage", location)) | ||
} | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
|
@@ -75,15 +119,15 @@ func TestAccAzureRMImage_requiresImport(t *testing.T) { | |
Steps: []resource.TestStep{ | ||
{ | ||
//need to create a vm and then reference it in the image creation | ||
Config: testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location), | ||
Config: testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "LRS"), | ||
Destroy: false, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), | ||
testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), | ||
), | ||
}, | ||
{ | ||
Config: testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location), | ||
Config: testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "LRS"), | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMImageExists("azurerm_image.test", true), | ||
), | ||
|
@@ -397,7 +441,7 @@ func testCheckAzureRMImageDestroy(s *terraform.State) error { | |
return nil | ||
} | ||
|
||
func testAccAzureRMImage_standaloneImage_setup(rInt int, userName string, password string, hostName string, location string) string { | ||
func testAccAzureRMImage_standaloneImage_setup(rInt int, userName string, password string, hostName string, location string, storageType string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
|
@@ -444,7 +488,7 @@ resource "azurerm_storage_account" "test" { | |
resource_group_name = "${azurerm_resource_group.test.name}" | ||
location = "${azurerm_resource_group.test.location}" | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
account_replication_type = "%s" | ||
|
||
tags = { | ||
environment = "Dev" | ||
|
@@ -495,10 +539,10 @@ resource "azurerm_virtual_machine" "testsource" { | |
cost-center = "Ops" | ||
} | ||
} | ||
`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password) | ||
`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, storageType, userName, password) | ||
} | ||
|
||
func testAccAzureRMImage_standaloneImage_provision(rInt int, userName string, password string, hostName string, location string) string { | ||
func testAccAzureRMImage_standaloneImage_provision(rInt int, userName string, password string, hostName string, location string, storageType string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
|
@@ -545,7 +589,7 @@ resource "azurerm_storage_account" "test" { | |
resource_group_name = "${azurerm_resource_group.test.name}" | ||
location = "${azurerm_resource_group.test.location}" | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
account_replication_type = "%s" | ||
|
||
tags = { | ||
environment = "Dev" | ||
|
@@ -601,6 +645,7 @@ resource "azurerm_image" "test" { | |
name = "accteste" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
zone_redundant = %t | ||
Lucretius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
os_disk { | ||
os_type = "Linux" | ||
|
@@ -615,11 +660,11 @@ resource "azurerm_image" "test" { | |
cost-center = "Ops" | ||
} | ||
} | ||
`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password) | ||
`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, storageType, userName, password, storageType == "ZRS") | ||
} | ||
|
||
func testAccAzureRMImage_standaloneImage_requiresImport(rInt int, userName string, password string, hostName string, location string) string { | ||
template := testAccAzureRMImage_standaloneImage_provision(rInt, userName, password, hostName, location) | ||
template := testAccAzureRMImage_standaloneImage_provision(rInt, userName, password, hostName, location, "LRS") | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
|
@@ -1388,3 +1433,14 @@ resource "azurerm_virtual_machine_scale_set" "testdestination" { | |
} | ||
`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password, rInt, userName, password, rInt) | ||
} | ||
|
||
// Region list pulled from https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy-zrs | ||
func supportsZRS(location string) bool { | ||
zrsRegions := []string{"westus2", "francecentral", "southeastasia", "westeurope", "northeurope", "japaneast", "uksouth", "eastus", "eastus2", "centralus"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this only covers Azure Public (there's different Azure Regions which are supported e.g. Government, China, Germany) - as such I think we'd be best to remove this for the moment? (we're running the tests in some of these regions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, my concern had been that I did not know in which locations these tests were going to be run, and did not want to have an acceptance test failure simply due to the fact that ZRS storage is not supported in some locations. |
||
for _, region := range zrsRegions { | ||
if region == location { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,11 +58,14 @@ The following arguments are supported: | |
the image. Changing this forces a new resource to be created. | ||
* `location` - (Required) Specified the supported Azure location where the resource exists. | ||
Changing this forces a new resource to be created. | ||
* `zone_resilient` - (Optional) Is zone resiliency enabled? Defaults to `false`. Changing this forces a new resource to be created. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're trying to keep these sorted Required -> Optional and then Alphabetically within the fields; could we move this to below Tags (and above the |
||
* `source_virtual_machine_id` - (Optional) The Virtual Machine ID from which to create the image. | ||
* `os_disk` - (Optional) One or more `os_disk` elements as defined below. | ||
* `data_disk` - (Optional) One or more `data_disk` elements as defined below. | ||
* `tags` - (Optional) A mapping of tags to assign to the resource. | ||
|
||
~> **Note**: `zone_resilient` can only be set to `true` if the image is stored in a region that supports availability zones. | ||
|
||
`os_disk` supports the following: | ||
|
||
* `os_type` - (Required) Specifies the type of operating system contained in the the virtual machine image. Possible values are: Windows or Linux. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we set this field in the state here: https://github.com/terraform-providers/terraform-provider-azurerm/pull/3100/files#diff-21521ec4fe0d38353d87860312cd25a4R187
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch thanks!