From 2070bc62703fe3d93d6d3d81a8f415b944b40263 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 18 Jan 2019 00:11:07 -0800 Subject: [PATCH] azurerm_cosmosdb_account: allow an empty value for ip filter property --- azurerm/resource_arm_cosmos_db_account.go | 2 +- .../resource_arm_cosmos_db_account_test.go | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmos_db_account.go index 7774bd02171a..af703e322ced 100644 --- a/azurerm/resource_arm_cosmos_db_account.go +++ b/azurerm/resource_arm_cosmos_db_account.go @@ -75,7 +75,7 @@ func resourceArmCosmosDBAccount() *schema.Resource { Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringMatch( - regexp.MustCompile(`^(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([1-2][0-9]|3[0-2]))?\b[,]?){1,}$`), + regexp.MustCompile(`^(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([1-2][0-9]|3[0-2]))?\b[,]?)*$`), "Cosmos DB ip_range_filter must be a set of CIDR IP addresses separated by commas with no spaces: '10.0.0.1,10.0.0.2,10.20.0.0/16'", ), }, diff --git a/azurerm/resource_arm_cosmos_db_account_test.go b/azurerm/resource_arm_cosmos_db_account_test.go index 0c2caed40d0b..d5ef07b7c2b3 100644 --- a/azurerm/resource_arm_cosmos_db_account_test.go +++ b/azurerm/resource_arm_cosmos_db_account_test.go @@ -507,6 +507,32 @@ func TestAccAzureRMCosmosDBAccount_complete(t *testing.T) { }) } +func TestAccAzureRMCosmosDBAccount_emptyIpFilter(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_emptyIpFilter(ri, testLocation(), testAltLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 2), + resource.TestCheckResourceAttr(resourceName, "ip_range_filter", ""), + resource.TestCheckResourceAttr(resourceName, "enable_automatic_failover", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMCosmosDBAccount_multiMaster(t *testing.T) { ri := tf.AccRandTimeInt() resourceName := "azurerm_cosmosdb_account.test" @@ -724,6 +750,19 @@ func testAccAzureRMCosmosDBAccount_complete(rInt int, location string, altLocati `, rInt, altLocation)) } +func testAccAzureRMCosmosDBAccount_emptyIpFilter(rInt int, location string, altLocation string) string { + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` + ip_range_filter = "" + enable_automatic_failover = true + + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + `, rInt, altLocation)) +} + func testAccAzureRMCosmosDBAccount_virtualNetworkFilter(rInt int, location string) string { vnetConfig := fmt.Sprintf(` resource "azurerm_virtual_network" "test" {