From 92098da78de64fa1839c6681bafa991ffbad77be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20K=C3=BCrner?= Date: Fri, 6 Sep 2019 23:39:51 +0200 Subject: [PATCH] r/cosmosdb_account: skip validation for geoReplicated non BoundedStaleness ConsistencyLevel Skip validation for BoundedStaleness specific ConsistencyLevel while configuring a geo replicated cosmosdb account with a non BoundedStaleness ConsistencyPolicy --- azurerm/resource_arm_cosmosdb_account.go | 3 +- azurerm/resource_arm_cosmosdb_account_test.go | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_cosmosdb_account.go b/azurerm/resource_arm_cosmosdb_account.go index 9421bedcf6ef..d4c532b9eba4 100644 --- a/azurerm/resource_arm_cosmosdb_account.go +++ b/azurerm/resource_arm_cosmosdb_account.go @@ -378,7 +378,8 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) // additional validation on MaxStalenessPrefix as it varies depending on if the DB is multi region or not - if cp := account.DatabaseAccountCreateUpdateProperties.ConsistencyPolicy; len(geoLocations) > 1 && cp != nil { + cp := account.DatabaseAccountCreateUpdateProperties.ConsistencyPolicy + if len(geoLocations) > 1 && cp != nil && cp.DefaultConsistencyLevel == documentdb.BoundedStaleness { if msp := cp.MaxStalenessPrefix; msp != nil && *msp < 100000 { return fmt.Errorf("Error max_staleness_prefix (%d) must be greater then 100000 when more then one geo_location is used", *msp) } diff --git a/azurerm/resource_arm_cosmosdb_account_test.go b/azurerm/resource_arm_cosmosdb_account_test.go index e8521dafce56..2861ad1a3e6b 100644 --- a/azurerm/resource_arm_cosmosdb_account_test.go +++ b/azurerm/resource_arm_cosmosdb_account_test.go @@ -477,6 +477,30 @@ func TestAccAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T) { }) } +func TestAccAzureRMCosmosDBAccount_geoReplicated_non_boundedStaleness_cp(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(ri, testLocation(), testAltLocation(), documentdb.Session), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.Session), 2), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMCosmosDBAccount_geoReplicated_add_remove(t *testing.T) { ri := tf.AccRandTimeInt() resourceName := "azurerm_cosmosdb_account.test" @@ -873,6 +897,18 @@ func testAccAzureRMCosmosDBAccount_geoReplicated_customId(rInt int, location str `, rInt, altLocation)) } +func testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(rInt int, location string, altLocation string, cLevel documentdb.DefaultConsistencyLevel) string { + + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(cLevel), "", fmt.Sprintf(` + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + + `, rInt, altLocation)) +} + func testAccAzureRMCosmosDBAccount_complete(rInt int, location string, altLocation string) string { co := ` max_interval_in_seconds = 373