DEV Community

Dina Berry
Dina Berry

Posted on • Originally published at dfberry.github.io on

Add Azure Developer CLI deployment ID and UTC timestamp to Bicep files

If you frequently deploy to Azure with Azure Developer CLI, either through your local computer or through an automated pipeline, you need a quick and obvious way to track back from the Azure resource to the pipeline or deployment.

In order to mark the deployment resource itself, use the Azure Developer CLI's deployment().name and the Bicep utcNow() function to mark your deployments. The deployment().name is the name of your environment and a timestamp (expressed as a unix timestamp).

To use these in your bicep file, a sample snippet of code is provided:

param deploymentDateTimeUtc string = utcNow()
param deploymentName string = deployment().name
Enter fullscreen mode Exit fullscreen mode

You can use these variables in your Bicep to add as tags to your resources.

var tags = {
  'azd-env-name': environmentName
  'azd-deployment-id': deploymentName
  'azd-deployment-utc': deploymentDateTimeUtc
}
Enter fullscreen mode Exit fullscreen mode

You can also export the variables as an environment variable to use in post-processing activities.

output DEPLOYMENT_NAME string = deploymentName
output DEPLOYMENT_DATETIME_UTC string = deploymentDateTimeUtc
Enter fullscreen mode Exit fullscreen mode

If you are using Terraform instead of Bicep, with Azure Developer CLI, you still have access to the deployment name but the utcNow() is not available.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay