1

I need to edit an existing powershell runbook which uses a template to create a cosmosDb in Azure.

I need to enable TTL without a default TTL value, in the examples I found so far there is always a value, this means that this value is used to delete expired documents.

How do I enable only the TTL without setting a default?

My reference: https://learn.microsoft.com/en-us/azure/cosmos-db/manage-with-powershell#create-container-unique-key-ttl

1 Answer 1

1

After digging in the Microsoft documentation I found this key table with examples:

+-------------+--------------------------------------------------------------------+
| TTL on item |                               Result                               |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to null (DefaultTimeToLive = null)                       |
|                                                                                  |
| ttl = null  | TTL is disabled. The item will never expire (default).             |
| ttl = -1    | TTL is disabled. The item will never expire.                       |
| ttl = 2000  | TTL is disabled. The item will never expire.                       |
|             |                                                                    |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to -1 (DefaultTimeToLive = -1)                           |                                                                                  |
|                                                                                  |
| ttl = null  | TTL is enabled. The item will never expire (default).              |
| ttl = -1    | TTL is enabled. The item will never expire.                        |
| ttl = 2000  | TTL is enabled. The item will expire after 2000 seconds.           |
|             |                                                                    |
+-------------+--------------------------------------------------------------------+
| TTL on container is set to 1000 (DefaultTimeToLive = 1000)                                          |
|                                                                                  |
| ttl = null  | TTL is enabled. The item will expire after 1000 seconds (default). |
| ttl = -1    | TTL is enabled. The item will never expire.                        |
| ttl = 2000  | TTL is enabled. The item will expire after 2000 seconds.           |
+-------------+--------------------------------------------------------------------+

This is not exactly referred to runbook and template but if I set -1 I can achieve my intent, as shown in the table above, setting in the container a TTL -1, this will be enabled and the TTL value in the documents will be used.

Using Get-Help New-CosmosDbCollection -full I could find the parameter -DefaultTimeToLive, this is what I am going to use because it looks like there is no option to do it in the ARM Template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.