Skip to content

Commit

Permalink
update tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephybun committed Apr 5, 2024
1 parent 4006549 commit c007632
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 38 deletions.
198 changes: 170 additions & 28 deletions internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ func TestAccCosmosDBAccount_freeTier(t *testing.T) {
Config: r.freeTier(data, "GlobalDocumentDB", cosmosdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 1),
check.That(data.ResourceName).Key("enable_free_tier").HasValue("true"),
check.That(data.ResourceName).Key("free_tier_enabled").HasValue("true"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -960,7 +960,7 @@ func TestAccCosmosDBAccount_vNetFilters(t *testing.T) {
})
}

// todo remove for 4.0
// TODO 4.0 remove post 4.0
func TestAccCosmosDBAccount_vNetFiltersThreePointOh(t *testing.T) {
if features.FourPointOhBeta() {
t.Skip("this test requires 3.0 mode")
Expand Down Expand Up @@ -1354,7 +1354,7 @@ func TestAccCosmosDBAccount_gremlinDatabasesToRestore(t *testing.T) {
})
}

// todo remove for 4.0
// TODO 4.0 remove post 4.0
func TestAccCosmosDBAccount_ipRangeFiltersThreePointOh(t *testing.T) {
if features.FourPointOhBeta() {
t.Skip("this test requires 3.0 mode")
Expand Down Expand Up @@ -1387,6 +1387,55 @@ func TestAccCosmosDBAccount_ipRangeFiltersThreePointOh(t *testing.T) {
})
}

func TestAccCosmosDBAccount_supersededProperties(t *testing.T) {
if features.FourPointOhBeta() {
t.Skip("this test contains deprecated properties and can be removed post 4.0")
}

data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")
// Limited regional availability
data.Locations.Primary = "westeurope"
data.Locations.Secondary = "northeurope"
r := CosmosDBAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basicMongoDB(data, cosmosdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 1),
),
},
data.ImportStep(),
{
Config: r.supersededProperties(data, cosmosdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 2),
),
},
data.ImportStep(),
})
}

func TestAccCosmosDBAccount_supersededFreeTier(t *testing.T) {
if features.FourPointOhBeta() {
t.Skip("this test contains deprecated properties and can be removed post 4.0")
}

data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")
r := CosmosDBAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.supersededFreeTier(data, "GlobalDocumentDB", cosmosdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 1),
check.That(data.ResourceName).Key("enable_free_tier").HasValue("true"),
),
},
data.ImportStep(),
})
}

func TestAccCosmosDBAccount_ipRangeFilters(t *testing.T) {
if !features.FourPointOhBeta() {
t.Skip("this test requires 4.0 mode")
Expand Down Expand Up @@ -1695,7 +1744,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -1753,7 +1802,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -1818,7 +1867,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -1867,7 +1916,7 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "%s"
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
consistency_policy {
consistency_level = "BoundedStaleness"
Expand Down Expand Up @@ -1911,7 +1960,7 @@ resource "azurerm_cosmosdb_account" "test" {
name = "EnableMongo"
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
consistency_policy {
consistency_level = "BoundedStaleness"
Expand Down Expand Up @@ -1972,7 +2021,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -2037,7 +2086,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -2114,7 +2163,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -2186,7 +2235,7 @@ resource "azurerm_cosmosdb_account" "test" {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
Expand Down Expand Up @@ -2407,8 +2456,8 @@ resource "azurerm_cosmosdb_account" "test" {
name = "EnableMongo"
}
enable_multiple_write_locations = true
enable_automatic_failover = true
multiple_write_locations_enabled = true
automatic_failover_enabled = true
consistency_policy {
consistency_level = "%s"
Expand Down Expand Up @@ -2477,8 +2526,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -2518,8 +2567,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -2566,7 +2615,7 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "%s"
enable_free_tier = true
free_tier_enabled = true
consistency_policy {
consistency_level = "%s"
Expand Down Expand Up @@ -4509,8 +4558,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -4550,8 +4599,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -4591,8 +4640,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -4632,8 +4681,8 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "GlobalDocumentDB"
enable_multiple_write_locations = false
enable_automatic_failover = false
multiple_write_locations_enabled = false
automatic_failover_enabled = false
consistency_policy {
consistency_level = "Eventual"
Expand Down Expand Up @@ -4733,7 +4782,7 @@ resource "azurerm_cosmosdb_account" "test" {
virtual_network_rule {
id = azurerm_subnet.subnet2.id
}
enable_multiple_write_locations = true
multiple_write_locations_enabled = true
geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
Expand All @@ -4757,3 +4806,96 @@ resource "azurerm_cosmosdb_account" "test" {
}
`, r.completePreReqs(data), data.RandomInteger, string(kind), string(consistency), data.Locations.Secondary, data.Locations.Ternary)
}

func (CosmosDBAccountResource) supersededProperties(data acceptance.TestData, consistency cosmosdb.DefaultConsistencyLevel) string {
return fmt.Sprintf(`
variable "geo_location" {
type = list(object({
location = string
failover_priority = string
zone_redundant = bool
}))
default = [
{
location = "%s"
failover_priority = 0
zone_redundant = false
},
{
location = "%s"
failover_priority = 1
zone_redundant = true
}
]
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%d"
location = "%s"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "MongoDB"
capabilities {
name = "EnableMongo"
}
enable_multiple_write_locations = true
enable_automatic_failover = true
consistency_policy {
consistency_level = "%s"
}
dynamic "geo_location" {
for_each = var.geo_location
content {
location = geo_location.value.location
failover_priority = geo_location.value.failover_priority
zone_redundant = geo_location.value.zone_redundant
}
}
}
`, data.Locations.Primary, data.Locations.Secondary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(consistency))
}

func (CosmosDBAccountResource) supersededFreeTier(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%d"
location = "%s"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "%s"
enable_free_tier = true
consistency_policy {
consistency_level = "%s"
}
geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency))
}
8 changes: 3 additions & 5 deletions website/docs/d/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ The following attributes are exported:

* `ip_range_filter` - The current IP Filter for this CosmosDB account

* `enable_free_tier` - If Free Tier pricing option is enabled for this CosmosDB Account. You can have up to one free tier Azure Cosmos DB account per Azure subscription.
* `free_tier_enabled` - If Free Tier pricing option is enabled for this CosmosDB Account. You can have up to one free tier Azure Cosmos DB account per Azure subscription.

* `enable_automatic_failover` - If automatic failover is enabled for this CosmosDB Account.
* `automatic_failover_enabled` - If automatic failover is enabled for this CosmosDB Account.

* `capabilities` - Capabilities enabled on this Cosmos DB account.

* `is_virtual_network_filter_enabled` - If virtual network filtering is enabled for this Cosmos DB account.

* `virtual_network_rule` - Subnets that are allowed to access this CosmosDB account.

* `enable_multiple_write_locations` - If multiple write locations are enabled for this Cosmos DB account.
* `multiple_write_locations_enabled` - If multiple write locations are enabled for this Cosmos DB account.

`consistency_policy` The current consistency Settings for this CosmosDB account with the following properties:

Expand Down Expand Up @@ -93,8 +93,6 @@ The following attributes are exported:

* `secondary_readonly_key` - The secondary read-only key for the CosmosDB account.

* `connection_strings` - A list of connection strings available for this CosmosDB account.

* `primary_sql_connection_string` - The primary SQL connection string for the CosmosDB Account.

* `secondary_sql_connection_string` - The secondary SQL connection string for the CosmosDB Account.
Expand Down
Loading

0 comments on commit c007632

Please sign in to comment.