Support datetime function
Per Tao and Daniel it be useful if ARM Template and Bicep can provide a datetime function to convert to Unix datetime format?
That's a good idea. We should do both directions (to and from unix timestamp).
This would be really useful for setting a secret expiration.
This would be really useful for setting a secret expiration.
Exactly! This should be implemented in bicep at least.
For me, it would be sufficient enough if there was a toUnix() function and a now() function with addDays or something. This way you could do toUnix(now('days', 30)) and set the expiration date of a KV Secret to 30 days from now.
I would not mind if the calculated date represents 'transpile' time and not nessecarily execution time.
We recently added dateTimeFromEpoch and dateTimeToEpoch functions in v0.5.6. Do these help you accomplish what you are looking for?
cc @bmoore-msft
They are not yet documented unfortunately so people can know about them only if they follow some PRs.
e not yet documented unfortunately so people can know about them only if they follow some PRs.
I will try this today, but it sure looks like a solution at first glance
This works like a charm and totally solves my problem:
param now string = utcNow()
var expiryDate = dateTimeAdd(now, 'P14D')
resource keyVaultSecrets 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
name: 'secretName'
parent: keyVault
properties: {
value: superSecretValue
attributes: {
exp: dateTimeToEpoch(expiryDate)
}
}
}
Thanks @nikneem for testing. Will do the same, awesome, this makes our life so much easier! Good job team!
Closing as this looks resolved and +1 @nikneem -- thank you for testing. I also created a separate task to get the functions documented - thanks @stansz.