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 : Fix issue about enabling analytical storage for CosmosDB is forcing re-creation #19659

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 5 additions & 1 deletion internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func resourceCosmosDbAccount() *pluginsdk.Resource {
return old.(string) == string(documentdb.TypeContinuous) && new.(string) == string(documentdb.TypePeriodic)
}),

pluginsdk.ForceNewIfChange("analytical_storage_enabled", func(ctx context.Context, old, new, _ interface{}) bool {
// analytical_storage_enabled can not be changed after being set to true
return old.(bool) && !new.(bool)
}),

pluginsdk.CustomizeDiffShim(func(ctx context.Context, diff *pluginsdk.ResourceDiff, v interface{}) error {
caps := diff.Get("capabilities")
mongo34found := false
Expand Down Expand Up @@ -231,7 +236,6 @@ func resourceCosmosDbAccount() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"public_network_access_enabled": {
Expand Down
18 changes: 13 additions & 5 deletions internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,17 @@ func TestAccCosmosDBAccount_analyticalStorage(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual),
Config: r.analyticalStorage(data, "MongoDB", documentdb.DefaultConsistencyLevelStrong, false),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1),
checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1),
check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("false"),
),
},
data.ImportStep(),
{
Config: r.analyticalStorage(data, "MongoDB", documentdb.DefaultConsistencyLevelStrong, true),
Check: acceptance.ComposeAggregateTestCheckFunc(
checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1),
check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"),
),
},
Expand Down Expand Up @@ -2068,7 +2076,7 @@ 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 {
func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, enableAnalyticalStorage bool) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -2086,7 +2094,7 @@ resource "azurerm_cosmosdb_account" "test" {
offer_type = "Standard"
kind = "%s"

analytical_storage_enabled = true
analytical_storage_enabled = %t

consistency_policy {
consistency_level = "%s"
Expand All @@ -2097,7 +2105,7 @@ resource "azurerm_cosmosdb_account" "test" {
failover_priority = 0
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency))
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), enableAnalyticalStorage, string(consistency))
}

func (CosmosDBAccountResource) mongoAnalyticalStorage(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ resource "azurerm_cosmosdb_sql_container" "test" {
partition_key_path = "/definition/id"
analytical_storage_ttl = 600
}
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), data.RandomInteger, data.RandomInteger)
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual, true), data.RandomInteger, data.RandomInteger)
}

func (CosmosSqlContainerResource) analyticalStorageTTL_removed(data acceptance.TestData) string {
Expand All @@ -356,7 +356,7 @@ resource "azurerm_cosmosdb_sql_container" "test" {
database_name = azurerm_cosmosdb_sql_database.test.name
partition_key_path = "/definition/id"
}
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), data.RandomInteger, data.RandomInteger)
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual, true), data.RandomInteger, data.RandomInteger)
}

func (CosmosSqlContainerResource) update(data acceptance.TestData) string {
Expand Down