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

Fix Cosmos zone redundant update #9485

Merged
merged 2 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,19 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})

// get existing locations (if exists)
resp, err := client.Get(ctx, resourceGroup, name)

if err != nil {
return fmt.Errorf("Error making Read request on AzureRM CosmosDB Account '%s': %s", name, err)
}

oldLocations := make([]documentdb.Location, 0)
oldLocationsMap := map[string]documentdb.Location{}
for _, l := range *resp.FailoverPolicies {
for _, l := range *resp.Locations {
location := documentdb.Location{
ID: l.ID,
LocationName: l.LocationName,
FailoverPriority: l.FailoverPriority,
IsZoneRedundant: l.IsZoneRedundant,
}

oldLocations = append(oldLocations, location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,36 @@ func testAccAzureRMCosmosDBAccount_zoneRedundantWith(t *testing.T, kind document
})
}

func testAccAzureRMCosmosDBAccount_zoneRedundant_updateWith(t *testing.T, kind documentdb.DatabaseAccountKind) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMCosmosDBAccount_basic(data, kind, documentdb.Eventual),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1),
),
},
data.ImportStep(),
{
Config: testAccAzureRMCosmosDBAccount_zoneRedundantUpdate(data, kind, documentdb.Eventual),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 2),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMCosmosDBAccount_zoneRedundant_update_mongo(t *testing.T) {
testAccAzureRMCosmosDBAccount_zoneRedundant_updateWith(t, documentdb.MongoDB)
}

func TestAccAzureRMCosmosDBAccount_update_mongo(t *testing.T) {
testAccAzureRMCosmosDBAccount_updateWith(t, documentdb.MongoDB)
}
Expand All @@ -284,7 +314,6 @@ func TestAccAzureRMCosmosDBAccount_update_global(t *testing.T) {
func TestAccAzureRMCosmosDBAccount_update_parse(t *testing.T) {
testAccAzureRMCosmosDBAccount_updateWith(t, documentdb.Parse)
}

func testAccAzureRMCosmosDBAccount_updateWith(t *testing.T, kind documentdb.DatabaseAccountKind) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

Expand Down Expand Up @@ -908,6 +937,63 @@ resource "azurerm_cosmosdb_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency), data.Locations.Secondary)
}

func testAccAzureRMCosmosDBAccount_zoneRedundantUpdate(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string {
return fmt.Sprintf(`
variable "geo_location" {
type = list(object({
location = string
failover_priority = string
zone_redundant = bool
}))
default = [
{
location = "%s"
failover_priority = 0
zone_redundant = false
},
{
location = "%s"
failover_priority = 1
zone_redundant = true
}
]
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%d"
location = "%s"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "%s"
enable_multiple_write_locations = true
enable_automatic_failover = true
consistency_policy {
consistency_level = "%s"
}
dynamic "geo_location" {
for_each = var.geo_location
content {
location = geo_location.value.location
failover_priority = geo_location.value.failover_priority
zone_redundant = geo_location.value.zone_redundant
}
}
}
`, data.Locations.Primary, data.Locations.Secondary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency))
}

func testAccAzureRMCosmosDBAccount_vNetFiltersPreReqs(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down