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

Support for analytical_storage_ttl in azurerm_cosmosdb_cassandra_table #11755

Merged
merged 2 commits into from
May 18, 2021
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
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