Skip to content

Commit

Permalink
Merge pull request #24615 from neil-yechenwei/vanguardcosmosdbacct03
Browse files Browse the repository at this point in the history
`azurerm_cosmosdb_account` - support new property `partition_merge_enabled`
  • Loading branch information
jackofallops authored Jan 31, 2024
2 parents 7561c11 + d559964 commit 75493c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
12 changes: 11 additions & 1 deletion internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ func resourceCosmosDbAccount() *pluginsdk.Resource {
},
},

"partition_merge_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"backup": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -750,6 +756,7 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{})
enableFreeTier := d.Get("enable_free_tier").(bool)
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)
partitionMergeEnabled := d.Get("partition_merge_enabled").(bool)
enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool)
disableLocalAuthentication := d.Get("local_authentication_disabled").(bool)

Expand Down Expand Up @@ -801,6 +808,7 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{})
Capabilities: capabilities,
VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d),
EnableMultipleWriteLocations: utils.Bool(enableMultipleWriteLocations),
EnablePartitionMerge: pointer.To(partitionMergeEnabled),
PublicNetworkAccess: pointer.To(publicNetworkAccess),
EnableAnalyticalStorage: utils.Bool(enableAnalyticalStorage),
Cors: common.ExpandCosmosCorsRule(d.Get("cors_rule").([]interface{})),
Expand Down Expand Up @@ -997,7 +1005,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
"capacity", "create_mode", "restore", "key_vault_key_id", "mongo_server_version",
"public_network_access_enabled", "ip_range_filter", "offer_type", "is_virtual_network_filter_enabled",
"kind", "tags", "enable_free_tier", "enable_automatic_failover", "analytical_storage_enabled",
"local_authentication_disabled") {
"local_authentication_disabled", "partition_merge_enabled") {
updateRequired = true
}

Expand Down Expand Up @@ -1044,6 +1052,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
NetworkAclBypassResourceIds: utils.ExpandStringSlice(d.Get("network_acl_bypass_ids").([]interface{})),
DisableLocalAuth: disableLocalAuthentication,
BackupPolicy: backup,
EnablePartitionMerge: pointer.To(d.Get("partition_merge_enabled").(bool)),
},
Tags: t,
}
Expand Down Expand Up @@ -1327,6 +1336,7 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er
d.Set("public_network_access_enabled", pointer.From(props.PublicNetworkAccess) == cosmosdb.PublicNetworkAccessEnabled)
d.Set("default_identity_type", props.DefaultIdentity)
d.Set("create_mode", pointer.From(props.CreateMode))
d.Set("partition_merge_enabled", pointer.From(props.EnablePartitionMerge))

if v := existing.Model.Properties.IsVirtualNetworkFilterEnabled; v != nil {
d.Set("is_virtual_network_filter_enabled", props.IsVirtualNetworkFilterEnabled)
Expand Down
21 changes: 11 additions & 10 deletions internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func testAccCosmosDBAccount_updateConsistency(t *testing.T, kind cosmosdb.Databa
},
data.ImportStep(),
{
Config: r.consistency(data, kind, cosmosdb.DefaultConsistencyLevelStrong, 8, 880),
Config: r.consistency(data, kind, false, cosmosdb.DefaultConsistencyLevelStrong, 8, 880),
Check: checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelStrong, 1),
},
data.ImportStep(),
Expand All @@ -430,12 +430,12 @@ func testAccCosmosDBAccount_updateConsistency(t *testing.T, kind cosmosdb.Databa
},
data.ImportStep(),
{
Config: r.consistency(data, kind, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 7, 770),
Config: r.consistency(data, kind, true, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 7, 770),
Check: checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 1),
},
data.ImportStep(),
{
Config: r.consistency(data, kind, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 77, 700),
Config: r.consistency(data, kind, false, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 77, 700),
Check: checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelBoundedStaleness, 1),
},
data.ImportStep(),
Expand Down Expand Up @@ -1441,7 +1441,7 @@ resource "azurerm_cosmosdb_account" "import" {
`, r.basic(data, "GlobalDocumentDB", consistency))
}

func (CosmosDBAccountResource) consistency(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel, interval, staleness int) string {
func (CosmosDBAccountResource) consistency(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, partitionMergeEnabled bool, consistency cosmosdb.DefaultConsistencyLevel, interval, staleness int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -1453,11 +1453,12 @@ resource "azurerm_resource_group" "test" {
}
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"
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "%s"
partition_merge_enabled = %t
consistency_policy {
consistency_level = "%s"
Expand All @@ -1470,7 +1471,7 @@ resource "azurerm_cosmosdb_account" "test" {
failover_priority = 0
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency), interval, staleness)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), partitionMergeEnabled, string(consistency), interval, staleness)
}

func (CosmosDBAccountResource) consistencyMongoDB(data acceptance.TestData, consistency cosmosdb.DefaultConsistencyLevel, interval, staleness int) string {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ The following arguments are supported:

* `enable_automatic_failover` - (Optional) Enable automatic failover for this Cosmos DB account.

* `partition_merge_enabled` - (Optional) Is partition merge on the Cosmos DB account enabled? Defaults to `false`.

* `public_network_access_enabled` - (Optional) Whether or not public network access is allowed for this CosmosDB account. Defaults to `true`.

* `capabilities` - (Optional) The capabilities which should be enabled for this Cosmos DB account. Value is a `capabilities` block as defined below.
Expand Down

0 comments on commit 75493c5

Please sign in to comment.