Skip to content

Commit

Permalink
azurerm_cosmosdb_account: correctly validate `max_interval_in_s… (#4273)
Browse files Browse the repository at this point in the history
Fixes #4118
  • Loading branch information
dkuerner authored and katbyte committed Sep 10, 2019
1 parent 70a7a97 commit 9a2796a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion azurerm/resource_arm_cosmosdb_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
36 changes: 36 additions & 0 deletions azurerm/resource_arm_cosmosdb_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a2796a

Please sign in to comment.