Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure ARM-template Date or Time function

I'm struggeling with azure ARM-templates and wanted to know if there is a way to concatenate the current date into a deployment name.

I'm looking for something like this.

"name" : "[concat('MYNAME',DATE('YYYY-MM-DD'))]"

Is there any way to do this? Or are there any plans to implement this in the future?

like image 392
Pablo Jomer Avatar asked Dec 01 '16 08:12

Pablo Jomer


2 Answers

Use utcNow() function to get date/time during deployment time. Note you can use it only in parameter's default value:

docs: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-functions-string#utcnow

"parameters" : { "todayUtc": { "type": "string", "defaultValue": "[utcNow('yyyy-MM-dd')]" } }

like image 199
okko Avatar answered Oct 19 '22 03:10

okko


Create a new parameter in your ARM template. In your powershell script that deploys the template, create a date variable like so:

$timestamp = get-date -Format "yyyy MM dd"

Then pass this to the template parameter inline with New-AzureRmResourceGroupDeployment like this (also, you can see the deployment name also uses a date from powershell. See this link for how to format the date):

New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
                                   -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile `
                                   -TemplateParameterFile $TemplateParametersFile `
                                   -date $timestamp
like image 30
Edward Rixon Avatar answered Oct 19 '22 05:10

Edward Rixon