From 9681fc7c368dca92280fa0b0024f5d23ab860f39 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 23 Jul 2019 14:01:45 -0700 Subject: [PATCH] =?UTF-8?q?azurerm=5Fcosmosdb=5Faccount:=20validate=20max?= =?UTF-8?q?=5Finterval=5Fin=5Fseconds=20and=E2=80=A6=20(#3906)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #3551 --- azurerm/resource_arm_cosmosdb_account.go | 15 ++++++-- ...urce_arm_cosmosdb_account_failover_test.go | 4 +-- azurerm/resource_arm_cosmosdb_account_test.go | 34 ++++++++++++++++--- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_cosmosdb_account.go b/azurerm/resource_arm_cosmosdb_account.go index 5bd18d1f1bbd..a1da3d617c69 100644 --- a/azurerm/resource_arm_cosmosdb_account.go +++ b/azurerm/resource_arm_cosmosdb_account.go @@ -110,14 +110,14 @@ func resourceArmCosmosDbAccount() *schema.Resource { Type: schema.TypeInt, Optional: true, Default: 5, - ValidateFunc: validation.IntBetween(5, 86400), + ValidateFunc: validation.IntBetween(5, 86400), // single region values }, "max_staleness_prefix": { Type: schema.TypeInt, Optional: true, Default: 100, - ValidateFunc: validation.IntBetween(10, 2147483647), + ValidateFunc: validation.IntBetween(10, 1000000), // single region values }, }, }, @@ -373,6 +373,17 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) Tags: expandTags(tags), } + // 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 { + 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) + } + if mis := cp.MaxIntervalInSeconds; mis != nil && *mis < 300 { + return fmt.Errorf("Error max_interval_in_seconds (%d) must be greater then 300 (5min) when more then one geo_location is used", *mis) + } + } + resp, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account) if err != nil { return fmt.Errorf("Error creating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) diff --git a/azurerm/resource_arm_cosmosdb_account_failover_test.go b/azurerm/resource_arm_cosmosdb_account_failover_test.go index 0a4288d75f2d..d515c674e9d8 100644 --- a/azurerm/resource_arm_cosmosdb_account_failover_test.go +++ b/azurerm/resource_arm_cosmosdb_account_failover_test.go @@ -315,8 +315,8 @@ resource "azurerm_cosmosdb_account" "test" { consistency_policy { consistency_level = "BoundedStaleness" - max_interval_in_seconds = 10 - max_staleness_prefix = 200 + max_interval_in_seconds = 333 + max_staleness_prefix = 101101 } failover_policy { diff --git a/azurerm/resource_arm_cosmosdb_account_test.go b/azurerm/resource_arm_cosmosdb_account_test.go index b24186b58d68..a0e5f4273472 100644 --- a/azurerm/resource_arm_cosmosdb_account_test.go +++ b/azurerm/resource_arm_cosmosdb_account_test.go @@ -825,7 +825,12 @@ func testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(rInt int, location stri } func testAccAzureRMCosmosDBAccount_geoReplicated(rInt int, location string, altLocation string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` geo_location { location = "%s" failover_priority = 1 @@ -835,7 +840,12 @@ func testAccAzureRMCosmosDBAccount_geoReplicated(rInt int, location string, altL } func testAccAzureRMCosmosDBAccount_multiMaster(rInt int, location string, altLocation string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` enable_multiple_write_locations = true geo_location { @@ -847,7 +857,12 @@ func testAccAzureRMCosmosDBAccount_multiMaster(rInt int, location string, altLoc } func testAccAzureRMCosmosDBAccount_geoReplicated_customId(rInt int, location string, altLocation string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` geo_location { prefix = "acctest-%d-custom-id" location = "%s" @@ -858,7 +873,11 @@ func testAccAzureRMCosmosDBAccount_geoReplicated_customId(rInt int, location str } func testAccAzureRMCosmosDBAccount_complete(rInt int, location string, altLocation string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` ip_range_filter = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16" enable_automatic_failover = true @@ -871,7 +890,12 @@ func testAccAzureRMCosmosDBAccount_complete(rInt int, location string, altLocati } func testAccAzureRMCosmosDBAccount_emptyIpFilter(rInt int, location string, altLocation string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` ip_range_filter = "" enable_automatic_failover = true