Skip to content

Commit

Permalink
azurerm_cosmosdb_account: enable_analytical_storage (#10055)
Browse files Browse the repository at this point in the history
  • Loading branch information
favoretti authored Jan 14, 2021
1 parent 289f1f6 commit 854cdf3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
13 changes: 13 additions & 0 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -227,6 +234,7 @@ func resourceCosmosDbAccount() *schema.Resource {
"mongoEnableDocLevelTTL",
"DisableRateLimitingResponses",
"AllowSelfServeUpgradeToMongo36",
// TODO: Remove in 3.0 - doesn't do anything
"EnableAnalyticalStorage",
}, true),
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.

Expand Down

0 comments on commit 854cdf3

Please sign in to comment.