Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_account: enable_analytical_storage #10055

Merged
merged 6 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
favoretti marked this conversation as resolved.
Show resolved Hide resolved
}, 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