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?
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')]" } }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With