Skip to content

Commit

Permalink
Support for analytical_storage_ttl in `azurerm_cosmosdb_cassandra_t…
Browse files Browse the repository at this point in the history
  • Loading branch information
yupwei68 authored and favoretti committed May 26, 2021
1 parent 90b2739 commit d1de789
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func resourceCosmosDbCassandraTable() *schema.Resource {
ValidateFunc: validation.IntAtLeast(-1),
},

"analytical_storage_ttl": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: -2,
ValidateFunc: validation.IntAtLeast(-1),
},

"schema": common.CassandraTableSchemaPropertySchema(),

"throughput": {
Expand Down Expand Up @@ -115,6 +123,10 @@ func resourceCosmosDbCassandraTableCreate(d *schema.ResourceData, meta interface
table.CassandraTableCreateUpdateProperties.Resource.DefaultTTL = utils.Int32(int32(defaultTTL.(int)))
}

if analyticalTTL := d.Get("analytical_storage_ttl").(int); analyticalTTL != -2 {
table.CassandraTableCreateUpdateProperties.Resource.AnalyticalStorageTTL = utils.Int32(int32(analyticalTTL))
}

if throughput, hasThroughput := d.GetOk("throughput"); hasThroughput {
if throughput != 0 {
table.CassandraTableCreateUpdateProperties.Options.Throughput = common.ConvertThroughputFromResourceData(throughput)
Expand Down Expand Up @@ -184,7 +196,7 @@ func resourceCosmosDbCassandraTableUpdate(d *schema.ResourceData, meta interface
if err != nil {
if response.WasNotFound(throughputFuture.Response()) {
return fmt.Errorf("setting Throughput for %s: %+v - "+
"If the collection has not been created with an initial throughput, you cannot configure it later.", *id, err)
"If the collection has not been created with an initial throughput, you cannot configure it later", *id, err)
}
}

Expand Down Expand Up @@ -229,6 +241,12 @@ func resourceCosmosDbCassandraTableRead(d *schema.ResourceData, meta interface{}
d.Set("default_ttl", defaultTTL)
}

analyticalTTL := -2
if res.AnalyticalStorageTTL != nil {
analyticalTTL = int(*res.AnalyticalStorageTTL)
}
d.Set("analytical_storage_ttl", analyticalTTL)

if schema := res.Schema; schema != nil {
d.Set("schema", flattenTableSchema(schema))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ func TestAccCosmosDbCassandraTable_basic(t *testing.T) {
})
}

func TestAccCosmosDbCassandraTable_analyticalStorageTTL(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_table", "test")
r := CosmosDBCassandraTableResource{}

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

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

func (CosmosDBCassandraTableResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand All @@ -73,3 +89,72 @@ resource "azurerm_cosmosdb_cassandra_table" "test" {
}
`, CosmosDbCassandraKeyspaceResource{}.basic(data), data.RandomInteger)
}

func (CosmosDBCassandraTableResource) analyticalStorageTTLTemplate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%[1]d"
location = "%[2]s"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%[1]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "GlobalDocumentDB"
analytical_storage_enabled = true
consistency_policy {
consistency_level = "Strong"
}
capabilities {
name = "EnableCassandra"
}
geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
}
}
resource "azurerm_cosmosdb_cassandra_keyspace" "test" {
name = "acctest-%[1]d"
resource_group_name = azurerm_cosmosdb_account.test.resource_group_name
account_name = azurerm_cosmosdb_account.test.name
}
`, data.RandomInteger, data.Locations.Primary)
}

func (r CosmosDBCassandraTableResource) analyticalStorageTTL(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
resource "azurerm_cosmosdb_cassandra_table" "test" {
name = "acctest-CCASST-%[2]d"
cassandra_keyspace_id = azurerm_cosmosdb_cassandra_keyspace.test.id
analytical_storage_ttl = 0
schema {
column {
name = "test1"
type = "ascii"
}
column {
name = "test2"
type = "int"
}
partition_key {
name = "test1"
}
}
}
`, r.analyticalStorageTTLTemplate(data), data.RandomInteger)
}
4 changes: 4 additions & 0 deletions website/docs/r/cosmosdb_cassandra_table.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ The following arguments are supported:

* `throughput` - (Optional) The throughput of Cassandra KeySpace (RU/s). Must be set in increments of `100`. The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply.

* `default_ttl` - (Optional) Time to live of the Cosmos DB Cassandra table. Possible values are at least `-1`. `-1` means the Cassandra table never expires.

* `analytical_storage_ttl` - (Optional) Time to live of the Analytical Storage. Possible values are at least `-1`. `-1` means the Analytical Storage never expires. Changing this forces a new resource to be created.

~> **Note:** throughput has a maximum value of `1000000` unless a higher limit is requested via Azure Support

* `autoscale_settings` - (Optional) An `autoscale_settings` block as defined below. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply.
Expand Down

0 comments on commit d1de789

Please sign in to comment.