From 33b4b249a57413a2b50d58a47d5921378be62d38 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Tue, 5 Jan 2021 16:57:25 +0100 Subject: [PATCH 1/5] azurerm_cosmosdb_account: enable_analytical_storage Initial implementation assumed it's a capability, whereas it's a property. This PR implements it properly. Fixes #9119 --- .../cosmos/cosmosdb_account_resource.go | 13 ++++- .../cosmos/cosmosdb_account_resource_test.go | 54 +++++++++++++++++++ website/docs/r/cosmosdb_account.html.markdown | 4 +- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go index 462c4a227257..a7924f805b17 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go @@ -111,6 +111,13 @@ func resourceArmCosmosDbAccount() *schema.Resource { ForceNew: true, }, + "enable_analytical_storage": { + Type: schema.TypeBool, + Optional: true, + Default: false, + ForceNew: true, + }, + "public_network_access_enabled": { Type: schema.TypeBool, Optional: true, @@ -227,7 +234,6 @@ func resourceArmCosmosDbAccount() *schema.Resource { "mongoEnableDocLevelTTL", "DisableRateLimitingResponses", "AllowSelfServeUpgradeToMongo36", - "EnableAnalyticalStorage", }, true), }, }, @@ -386,6 +392,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.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) + enableAnalyticalStorage := d.Get("enable_analytical_storage").(bool) r, err := client.CheckNameExists(ctx, name) if err != nil { @@ -423,6 +430,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d), EnableMultipleWriteLocations: utils.Bool(enableMultipleWriteLocations), PublicNetworkAccess: publicNetworkAccess, + EnableAnalyticalStorage: utils.Bool(enableAnalyticalStorage), }, Tags: tags.Expand(t), } @@ -481,6 +489,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.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) + enableAnalyticalStorage := d.Get("enable_analytical_storage").(bool) newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d) if err != nil { @@ -530,6 +539,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d), EnableMultipleWriteLocations: resp.EnableMultipleWriteLocations, PublicNetworkAccess: publicNetworkAccess, + EnableAnalyticalStorage: utils.Bool(enableAnalyticalStorage), }, Tags: tags.Expand(t), } @@ -629,6 +639,7 @@ func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) er d.Set("endpoint", resp.DocumentEndpoint) d.Set("enable_free_tier", resp.EnableFreeTier) + d.Set("enable_analytical_storage", 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 cb969d665aca..59e2385cb2d6 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -78,6 +78,10 @@ func TestAccAzureRMCosmosDBAccount_public_network_access_enabled(t *testing.T) { testAccAzureRMCosmosDBAccount_public_network_access_enabled(t, documentdb.MongoDB, documentdb.Strong) } +func TestAccAzureRMCosmosDBAccount_analytical_storage_enabled(t *testing.T) { + testAccAzureRMCosmosDBAccount_analytical_storage_enabled(t, documentdb.GlobalDocumentDB, documentdb.Session) +} + func testAccAzureRMCosmosDBAccount_public_network_access_enabled(t *testing.T, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") @@ -97,6 +101,25 @@ func testAccAzureRMCosmosDBAccount_public_network_access_enabled(t *testing.T, k }) } +func testAccAzureRMCosmosDBAccount_analytical_storage_enabled(t *testing.T, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: checkAccAzureRMCosmosDBAccount_analytical_storage_enabled(data, kind, consistency), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, consistency, 1), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccCosmosDBAccount_keyVaultUri(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") @@ -1179,6 +1202,37 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } +func checkAccAzureRMCosmosDBAccount_analytical_storage_enabled(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" + enable_analytical_storage = 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 checkAccAzureRMCosmosDBAccount_key_vault_uri(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` provider "azurerm" { diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 9b4bd219c2da..bbea0219698d 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. +* `enable_analytical_storage` - (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`. From 067b13594b8854b921cf5b9bf0409183728a16d6 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Tue, 5 Jan 2021 17:08:00 +0100 Subject: [PATCH 2/5] Terrafmt --- .../cosmos/cosmosdb_account_resource_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go index 59e2385cb2d6..edc19f725c77 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -1214,12 +1214,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" - enable_analytical_storage = true + name = "acctest-ca-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + offer_type = "Standard" + kind = "%s" + enable_analytical_storage = true consistency_policy { consistency_level = "%s" From e03c60373c0b1ac8de4d280689f2480e05c53b95 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Wed, 6 Jan 2021 15:35:29 +0100 Subject: [PATCH 3/5] Rebase, redo test in a new format --- .../cosmos/cosmosdb_account_resource.go | 2 + .../cosmos/cosmosdb_account_resource_test.go | 67 +++++++++++++------ 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go index 6819008561d7..40959802590f 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go @@ -234,6 +234,8 @@ func resourceCosmosDbAccount() *schema.Resource { "mongoEnableDocLevelTTL", "DisableRateLimitingResponses", "AllowSelfServeUpgradeToMongo36", + // TODO: Remove in 3.0 - doesn't do anything + "EnableAnalyticalStorage", }, true), }, }, diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go index 1b2ff1d074da..df14dd032c79 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -99,25 +99,6 @@ func testAccCosmosDBAccount_public_network_access_enabled(t *testing.T, kind doc }) } -func testAccAzureRMCosmosDBAccount_analytical_storage_enabled(t *testing.T, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) { - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: checkAccAzureRMCosmosDBAccount_analytical_storage_enabled(data, kind, consistency), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(data, consistency, 1), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccCosmosDBAccount_keyVaultUri(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -505,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("enable_analytical_storage").HasValue("true"), + ), + }, + data.ImportStep(), + }) +} + func TestAccCosmosDBAccount_vNetFilters(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -1052,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" + + enable_analytical_storage = 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(), From 0e69f1570c83f5d549a41f234f58e04d44d1160e Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Tue, 12 Jan 2021 14:30:22 +0100 Subject: [PATCH 4/5] Rename property --- .../internal/services/cosmos/cosmosdb_account_resource.go | 8 ++++---- .../services/cosmos/cosmosdb_account_resource_test.go | 2 +- website/docs/r/cosmosdb_account.html.markdown | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go index 40959802590f..b54e26d99e28 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource.go @@ -111,7 +111,7 @@ func resourceCosmosDbAccount() *schema.Resource { ForceNew: true, }, - "enable_analytical_storage": { + "analytical_storage_enabled": { Type: schema.TypeBool, Optional: true, Default: false, @@ -394,7 +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("enable_analytical_storage").(bool) + enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool) r, err := client.CheckNameExists(ctx, name) if err != nil { @@ -491,7 +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("enable_analytical_storage").(bool) + enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool) newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d) if err != nil { @@ -641,7 +641,7 @@ func resourceCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) error d.Set("endpoint", resp.DocumentEndpoint) d.Set("enable_free_tier", resp.EnableFreeTier) - d.Set("enable_analytical_storage", resp.EnableAnalyticalStorage) + 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 df14dd032c79..d33936d278f7 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -1067,7 +1067,7 @@ resource "azurerm_cosmosdb_account" "test" { offer_type = "Standard" kind = "%s" - enable_analytical_storage = true + analytical_storage_enabled = true consistency_policy { consistency_level = "%s" diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index bbea0219698d..769c25a954be 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -86,7 +86,7 @@ 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. -* `enable_analytical_storage` - (Optional) Enable Analytical Storage 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. From a107e5792b677e662264d5d39926a801297f5ae5 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Thu, 14 Jan 2021 09:56:47 +0100 Subject: [PATCH 5/5] Rename property in the test too, duh --- .../internal/services/cosmos/cosmosdb_account_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go index d33936d278f7..0ef89a1d6fa6 100644 --- a/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/azurerm/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -495,7 +495,7 @@ func TestAccCosmosDBAccount_analyticalStorage(t *testing.T) { Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.Eventual), Check: resource.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.Eventual, 1), - check.That(data.ResourceName).Key("enable_analytical_storage").HasValue("true"), + check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), ), }, data.ImportStep(),