Skip to content

Commit

Permalink
azurerm_cosmosdb_sql_container: add analytical_storage_ttl argume…
Browse files Browse the repository at this point in the history
…nt (#11655)

```
$ TF_ACC=1 go test -v ./azurerm/internal/services/cosmos -timeout=1000m -run 'TestAccCosmosDbSqlContainer_analyticalStorageTTL'
2021/05/11 10:28:44 [DEBUG] not using binary driver name, it's no longer needed
2021/05/11 10:28:47 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccCosmosDbSqlContainer_analyticalStorageTTL
=== PAUSE TestAccCosmosDbSqlContainer_analyticalStorageTTL
=== CONT  TestAccCosmosDbSqlContainer_analyticalStorageTTL
--- PASS: TestAccCosmosDbSqlContainer_analyticalStorageTTL (1009.36s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos	1017.167s

```

Fixes #10198
  • Loading branch information
favoretti authored May 14, 2021
1 parent 826ed68 commit 0de88db
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func resourceCosmosDbSQLContainer() *schema.Resource {

"autoscale_settings": common.DatabaseAutoscaleSettingsSchema(),

"analytical_storage_ttl": {
Type: schema.TypeInt,
Optional: true,
},

"default_ttl": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -156,9 +161,8 @@ func resourceCosmosDbSQLContainerCreate(d *schema.ResourceData, meta interface{}
db := documentdb.SQLContainerCreateUpdateParameters{
SQLContainerCreateUpdateProperties: &documentdb.SQLContainerCreateUpdateProperties{
Resource: &documentdb.SQLContainerResource{
ID: &name,
IndexingPolicy: indexingPolicy,

ID: &name,
IndexingPolicy: indexingPolicy,
ConflictResolutionPolicy: common.ExpandCosmosDbConflicResolutionPolicy(d.Get("conflict_resolution_policy").([]interface{})),
},
Options: &documentdb.CreateUpdateOptions{},
Expand All @@ -182,6 +186,10 @@ func resourceCosmosDbSQLContainerCreate(d *schema.ResourceData, meta interface{}
}
}

if analyticalStorageTTL, ok := d.GetOk("analytical_storage_ttl"); ok {
db.SQLContainerCreateUpdateProperties.Resource.AnalyticalStorageTTL = utils.Int64(int64(analyticalStorageTTL.(int)))
}

if defaultTTL, hasTTL := d.GetOk("default_ttl"); hasTTL {
db.SQLContainerCreateUpdateProperties.Resource.DefaultTTL = utils.Int32(int32(defaultTTL.(int)))
}
Expand Down Expand Up @@ -269,6 +277,10 @@ func resourceCosmosDbSQLContainerUpdate(d *schema.ResourceData, meta interface{}
}
}

if analyticalStorageTTL, ok := d.GetOk("analytical_storage_ttl"); ok {
db.SQLContainerCreateUpdateProperties.Resource.AnalyticalStorageTTL = utils.Int64(int64(analyticalStorageTTL.(int)))
}

if defaultTTL, hasTTL := d.GetOk("default_ttl"); hasTTL {
db.SQLContainerCreateUpdateProperties.Resource.DefaultTTL = utils.Int32(int32(defaultTTL.(int)))
}
Expand Down Expand Up @@ -348,6 +360,10 @@ func resourceCosmosDbSQLContainerRead(d *schema.ResourceData, meta interface{})
}
}

if analyticalStorageTTL := res.AnalyticalStorageTTL; analyticalStorageTTL != nil {
d.Set("analytical_storage_ttl", analyticalStorageTTL)
}

if defaultTTL := res.DefaultTTL; defaultTTL != nil {
d.Set("default_ttl", defaultTTL)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
Expand Down Expand Up @@ -65,6 +66,22 @@ func TestAccCosmosDbSqlContainer_complete(t *testing.T) {
})
}

func TestAccCosmosDbSqlContainer_analyticalStorageTTL(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test")
r := CosmosSqlContainerResource{}

data.ResourceTest(t, r, []resource.TestStep{
{

Config: r.analyticalStorageTTL(data),
Check: resource.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccCosmosDbSqlContainer_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test")
r := CosmosSqlContainerResource{}
Expand Down Expand Up @@ -289,6 +306,27 @@ resource "azurerm_cosmosdb_sql_container" "test" {
`, CosmosSqlDatabaseResource{}.basic(data), data.RandomInteger)
}

func (CosmosSqlContainerResource) analyticalStorageTTL(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"
analytical_storage_ttl = 600
}
`, CosmosDBAccountResource{}.analyticalStorage(data, "GlobalDocumentDB", documentdb.Eventual), data.RandomInteger, data.RandomInteger)
}

func (CosmosSqlContainerResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_sql_container.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ 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.

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

---
Expand Down

0 comments on commit 0de88db

Please sign in to comment.