diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go index e8cc96e0b28a..b54e26d99e28 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go @@ -111,6 +111,13 @@ func resourceCosmosDbAccount() *schema.Resource { ForceNew: true, }, + "analytical_storage_enabled": { + Type: schema.TypeBool, + Optional: true, + Default: false, + ForceNew: true, + }, + "public_network_access_enabled": { Type: schema.TypeBool, Optional: true, @@ -227,6 +234,7 @@ func resourceCosmosDbAccount() *schema.Resource { "mongoEnableDocLevelTTL", "DisableRateLimitingResponses", "AllowSelfServeUpgradeToMongo36", + // TODO: Remove in 3.0 - doesn't do anything "EnableAnalyticalStorage", }, true), }, @@ -386,6 +394,7 @@ func resourceCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) err enableFreeTier := d.Get("enable_free_tier").(bool) enableAutomaticFailover := d.Get("enable_automatic_failover").(bool) enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool) + enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool) r, err := client.CheckNameExists(ctx, name) if err != nil { @@ -423,6 +432,7 @@ func resourceCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) err VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d), EnableMultipleWriteLocations: utils.Bool(enableMultipleWriteLocations), PublicNetworkAccess: publicNetworkAccess, + EnableAnalyticalStorage: utils.Bool(enableAnalyticalStorage), }, Tags: tags.Expand(t), } @@ -481,6 +491,7 @@ func resourceCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) err enableFreeTier := d.Get("enable_free_tier").(bool) enableAutomaticFailover := d.Get("enable_automatic_failover").(bool) enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool) + enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool) newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d) if err != nil { @@ -530,6 +541,7 @@ func resourceCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) err VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d), EnableMultipleWriteLocations: resp.EnableMultipleWriteLocations, PublicNetworkAccess: publicNetworkAccess, + EnableAnalyticalStorage: utils.Bool(enableAnalyticalStorage), }, Tags: tags.Expand(t), } @@ -629,6 +641,7 @@ func resourceCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) error d.Set("endpoint", resp.DocumentEndpoint) d.Set("enable_free_tier", resp.EnableFreeTier) + d.Set("analytical_storage_enabled", resp.EnableAnalyticalStorage) d.Set("public_network_access_enabled", resp.PublicNetworkAccess == documentdb.Enabled) if v := resp.IsVirtualNetworkFilterEnabled; v != nil { diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go index 24203a58179f..0ef89a1d6fa6 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -486,6 +486,22 @@ func TestAccCosmosDBAccount_freeTier(t *testing.T) { }) } +func TestAccCosmosDBAccount_analyticalStorage(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + r := CosmosDBAccountResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.Eventual), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.Eventual, 1), + check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), + ), + }, + data.ImportStep(), + }) +} + func TestAccCosmosDBAccount_vNetFilters(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -1033,6 +1049,38 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } +func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.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" + + analytical_storage_enabled = 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)) +} + func checkAccCosmosDBAccount_basic(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel, locationCount int) resource.TestCheckFunc { return resource.ComposeTestCheckFunc( check.That(data.ResourceName).Key("name").Exists(), diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 9b4bd219c2da..769c25a954be 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -86,6 +86,8 @@ The following arguments are supported: * `enable_free_tier` - (Optional) Enable Free Tier pricing option for this Cosmos DB account. Defaults to `false`. Changing this forces a new resource to be created. +* `analytical_storage_enabled` - (Optional) Enable Analytical Storage option for this Cosmos DB account. Defaults to `false`. Changing this forces a new resource to be created. + * `enable_automatic_failover` - (Optional) Enable automatic fail over for this Cosmos DB account. * `public_network_access_enabled` - (Optional) Whether or not public network access is allowed for this CosmosDB account. @@ -120,7 +122,7 @@ The following arguments are supported: `capabilities` Configures the capabilities to enable for this Cosmos DB account: -* `name` - (Required) The capability to enable - Possible values are `AllowSelfServeUpgradeToMongo36`, `DisableRateLimitingResponses`, `EnableAggregationPipeline`, `EnableAnalyticalStorage`, `EnableCassandra`, `EnableGremlin`,`EnableMongo`, `EnableTable`, `EnableServerless`, `MongoDBv3.4` and `mongoEnableDocLevelTTL`. +* `name` - (Required) The capability to enable - Possible values are `AllowSelfServeUpgradeToMongo36`, `DisableRateLimitingResponses`, `EnableAggregationPipeline`, `EnableCassandra`, `EnableGremlin`,`EnableMongo`, `EnableTable`, `EnableServerless`, `MongoDBv3.4` and `mongoEnableDocLevelTTL`. **NOTE:** The `prefix` and `failover_priority` fields of a location cannot be changed for the location with a failover priority of `0`.