diff --git a/azurerm/resource_arm_cosmosdb_account.go b/azurerm/resource_arm_cosmosdb_account.go index cf9c2adb6cc2..f6af1a3b9b26 100644 --- a/azurerm/resource_arm_cosmosdb_account.go +++ b/azurerm/resource_arm_cosmosdb_account.go @@ -374,7 +374,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