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_sql_container: fix issue about removing analytical_storage_ttl needs to force replacement #16229

Merged
merged 1 commit into from
Apr 6, 2022
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
8 changes: 8 additions & 0 deletions internal/services/cosmos/cosmosdb_sql_container_resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cosmos

import (
"context"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -126,6 +127,13 @@ func resourceCosmosDbSQLContainer() *pluginsdk.Resource {
},
"indexing_policy": common.CosmosDbIndexingPolicySchema(),
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
// The analytical_storage_ttl cannot be changed back once enabled on an existing container. -> we need ForceNew
pluginsdk.ForceNewIfChange("analytical_storage_ttl", func(ctx context.Context, old, new, _ interface{}) bool {
return (old.(int) == -1 || old.(int) > 0) && new.(int) == 0
}),
),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ func TestAccCosmosDbSqlContainer_analyticalStorageTTL(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.analyticalStorageTTL_removed(data),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.analyticalStorageTTL(data),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand Down Expand Up @@ -325,6 +339,26 @@ resource "azurerm_cosmosdb_sql_container" "test" {
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), data.RandomInteger, data.RandomInteger)
}

func (CosmosSqlContainerResource) analyticalStorageTTL_removed(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s

resource "azurerm_cosmosdb_sql_database" "test" {
name = "acctest-%[2]d"
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name
account_name = azurerm_cosmosdb_account.test.name
}

resource "azurerm_cosmosdb_sql_container" "test" {
name = "acctest-CSQLC-%[2]d"
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name
account_name = azurerm_cosmosdb_account.test.name
database_name = azurerm_cosmosdb_sql_database.test.name
partition_key_path = "/definition/id"
}
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), data.RandomInteger, data.RandomInteger)
}

func (CosmosSqlContainerResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cosmosdb_sql_container.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The following arguments are supported:

* `default_ttl` - (Optional) The default time to live of SQL container. If missing, items are not expired automatically. If present and the value is set to `-1`, it is equal to infinity, and items don’t expire by default. If present and the value is set to some number `n` – items will expire `n` seconds after their last modified time.

* `analytical_storage_ttl` - (Optional) The default time to live of Analytical Storage for this SQL container. If present and the value is set to `-1`, it is equal to infinity, and items don’t expire by default. If present and the value is set to some number `n` – items will expire `n` seconds after their last modified time.
* `analytical_storage_ttl` - (Optional) The default time to live of Analytical Storage for this SQL container. If present and the value is set to `-1`, it is equal to infinity, and items don’t expire by default. If present and the value is set to some number `n` – items will expire `n` seconds after their last modified time. Changing this forces a new Cosmos DB SQL Container to be created when removing `analytical_storage_ttl` on an existing Cosmos DB SQL Container.

* `conflict_resolution_policy` - (Optional) A `conflict_resolution_policy` blocks as defined below.

Expand Down