Skip to content

Commit

Permalink
Fix Cosmos zoneRedundant update
Browse files Browse the repository at this point in the history
  • Loading branch information
kvendingoldo committed Nov 25, 2020
1 parent 32fc497 commit 365274a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
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,38 @@ func testAccAzureRMCosmosDBAccount_zoneRedundantWith(t *testing.T, kind document
})
}

// TODO: MY CODE
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, "GlobalDocumentDB", documentdb.Eventual),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1),
),
},
data.ImportStep(),
{
Config: testAccAzureRMCosmosDBAccount_zoneRedundantUpdate(data, "GlobalDocumentDB", documentdb.Eventual),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 2),
),
},
data.ImportStep(),
},
})
}

// TODO: MY CODE
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 +316,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 +939,60 @@ 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"
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ require (
gopkg.in/yaml.v2 v2.2.4
)

go 1.13
go 1.13
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,4 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

0 comments on commit 365274a

Please sign in to comment.