Skip to content

Commit

Permalink
azurerm_cosmosdb_gremlin_graph: Expose default_ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack authored and Jack committed Jan 12, 2021
1 parent 73c6c3c commit 52c121c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func resourceCosmosDbGremlinGraph() *schema.Resource {
ValidateFunc: validate.CosmosEntityName,
},

"default_ttl": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},

"throughput": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -233,6 +239,12 @@ func resourceCosmosDbGremlinGraphCreate(d *schema.ResourceData, meta interface{}
}
}

if defaultTTL, hasDefaultTTL := d.GetOk("default_ttl"); hasDefaultTTL {
if defaultTTL != 0 {
db.GremlinGraphCreateUpdateProperties.Resource.DefaultTTL = utils.Int32(int32(defaultTTL.(int)))
}
}

if throughput, hasThroughput := d.GetOk("throughput"); hasThroughput {
if throughput != 0 {
db.GremlinGraphCreateUpdateProperties.Options.Throughput = common.ConvertThroughputFromResourceData(throughput)
Expand Down Expand Up @@ -306,6 +318,10 @@ func resourceCosmosDbGremlinGraphUpdate(d *schema.ResourceData, meta interface{}
}
}

if defaultTTL, hasDefaultTTL := d.GetOk("default_ttl"); hasDefaultTTL {
db.GremlinGraphCreateUpdateProperties.Resource.DefaultTTL = utils.Int32(int32(defaultTTL.(int)))
}

future, err := client.CreateUpdateGremlinGraph(ctx, id.ResourceGroup, id.DatabaseAccountName, id.GremlinDatabaseName, id.GraphName, db)
if err != nil {
return fmt.Errorf("Error issuing create/update request for Cosmos Gremlin Graph %q (Account: %q, Database: %q): %+v", id.GraphName, id.DatabaseAccountName, id.GremlinDatabaseName, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ func TestAccCosmosDbGremlinGraph_update(t *testing.T) {

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.update(data, 700),
Config: r.update(data, 700, 900),
Check: resource.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("throughput").HasValue("700"),
check.That(data.ResourceName).Key("default_ttl").HasValue("900"),
),
},
data.ImportStep(),
{
Config: r.update(data, 1700),
Config: r.update(data, 1700, 1900),
Check: resource.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("throughput").HasValue("1700"),
check.That(data.ResourceName).Key("default_ttl").HasValue("1900"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -251,7 +253,7 @@ resource "azurerm_cosmosdb_gremlin_graph" "test" {
`, CosmosGremlinDatabaseResource{}.basic(data), data.RandomInteger)
}

func (CosmosGremlinGraphResource) update(data acceptance.TestData, throughput int) string {
func (CosmosGremlinGraphResource) update(data acceptance.TestData, throughput int, defaultTTL int) string {
return fmt.Sprintf(`
%[1]s
Expand All @@ -262,6 +264,7 @@ resource "azurerm_cosmosdb_gremlin_graph" "test" {
database_name = azurerm_cosmosdb_gremlin_database.test.name
partition_key_path = "/test"
throughput = %[3]d
default_ttl = %[4]d
index_policy {
automatic = true
Expand All @@ -279,7 +282,7 @@ resource "azurerm_cosmosdb_gremlin_graph" "test" {
paths = ["/definition/id1", "/definition/id2"]
}
}
`, CosmosGremlinDatabaseResource{}.basic(data), data.RandomInteger, throughput)
`, CosmosGremlinDatabaseResource{}.basic(data), data.RandomInteger, throughput, defaultTTL)
}

func (CosmosGremlinGraphResource) autoscale(data acceptance.TestData, maxThroughput int) string {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_gremlin_graph.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ The following arguments are supported:

* `throughput` - (Optional) The throughput of the Gremlin graph (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) The default time to live (TTL) of the Gremlin graph. If the value is missing or set to "-1", items don’t expire.

* `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. Requires `partition_key_path` to be set.

~> **Note:** Switching between autoscale and manual throughput is not supported via Terraform and must be completed via the Azure Portal and refreshed.
Expand Down

0 comments on commit 52c121c

Please sign in to comment.