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

azurerm_cosmosdb_account: correctly validate max_interval_in_seconds & max_staleness_prefix for geo replicated accounts #4273

Merged
merged 1 commit into from
Sep 10, 2019
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
3 changes: 2 additions & 1 deletion azurerm/resource_arm_cosmosdb_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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