Deploying a tag to a resource
In this guide, we'll walk through the steps to deploy a tag to a resource (group).
Tags are metadata elements that you apply to your Azure resources.
They're key-value pairs that help you identify resources based on settings that are relevant to your organization.
If you want to track the deployment environment for your resources, add a key named Environment.
To identify the resources deployed to production, give them a value of Production. The full key-value pair is Environment = Production.
Add the tag option
In Visual Studio Code go back to the file resourcegroup-networking.bicep
:
-
Add a new line under the line:
name: name
-
Type in the letter
t
, you will see an autocomplete option fortags:
-
Hit
tab
to select the option -
Hit
spacebar
andenter
on the suggested next option
-
You can now add tags to the resource (group)
tags: {
Environment: 'Production'
} -
Re-run the PowerShell to deploy the resource group
-
Refresh the resource group to see the newly created resource group
- A refresh can take a while, it's probably faster to tick another resource group (if you have one) and move back to this one or hit CTRL-F5 to refresh the complete browser
-
If all is correct you'll see the added tag set on the resource group
-
Add a new tag to the resource group via the Azure Portal, for example
Owner
with your name as value -
Re-run the PowerShell to deploy the resource group
-
Refresh the resource group to see that your
owner
tag is removed by the code (code is leading)- A refresh can take a while, it's probably faster to tick another resource group (if you have one) and move back to this one or hit CTRL-F5 to refresh the complete browser
-
If you want the owner tag applied to the resource group, you need to add it to the code and redeploy the resource group:
tags: {
Environment: 'Production'
Owner: 'YourName'
}
-
Template
Your template resourcegroup-networking.bicep
should look like this:
targetScope = 'subscription'
param location string = 'westeurope'
param name string = 'rg-networking'
resource resResourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = {
location: location
name: name
tags: {
Environment: 'Production'
Owner: 'DTX Demo'
}
}
Version overview
This document has the following versions:
Version | Date | Overview of changes |
---|---|---|
1.0 | 2024-03-18 | Initial version. |