diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 7740e3d1e5a1..124fe48ee2d9 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -505,6 +505,12 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, }, + "partition_merge_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + "backup": { Type: pluginsdk.TypeList, Optional: true, @@ -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) @@ -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{})), @@ -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 } @@ -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, } @@ -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) diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index fb4f08e5727f..a7ed7274c03a 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -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(), @@ -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(), @@ -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 {} @@ -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" @@ -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 { diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 3c30ec3a9563..d14da042af98 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -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.