Skip to content

Commit

Permalink
azurerm_cosmosdb_account: allow an empty value for ip filter property (
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte authored Jan 18, 2019
1 parent 4177a8e commit 9175c6c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
),
},
Expand Down
39 changes: 39 additions & 0 deletions azurerm/resource_arm_cosmos_db_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,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"
Expand Down Expand Up @@ -675,6 +701,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" {
Expand Down

0 comments on commit 9175c6c

Please sign in to comment.