Skip to content

Commit

Permalink
Add default tags to Bicep examples (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooke-hamilton authored Jan 18, 2022
1 parent 7a8592a commit 88e3a45
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 46 deletions.
12 changes: 12 additions & 0 deletions src/bicep/examples/appServicePlan/appService.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ param enableAutoScale bool = true
@description('Defines the performance tier of your web farm. By default the performance scale will be premium 2nd generation version 2 "p2v2". Another value would be standard generation 2 "s2".')
param appServiceSkuName string = 'p2v2'

@description('A string dictionary of tags to add to deployed resources. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources?tabs=json#arm-templates for valid settings.')
param tags object = {}
var defaultTags = {
'DeploymentType': 'MissionLandingZoneARM'
}
var calculatedTags = union(tags, defaultTags)

var targetSubscriptionId_Var = targetResourceGroup == '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}' ? '${mlzDeploymentVariables.spokes.Value[2].subscriptionId}' : subscription().subscriptionId
var location = deployment().location
var kind = 'linux'
Expand All @@ -26,6 +33,7 @@ var capacity = 2
resource targetASPResourceGroup 'Microsoft.Resources/resourceGroups@2020-10-01' = {
name: targetResourceGroup
location: location
tags: calculatedTags
}

module appServicePlan 'modules/appServicePlan.bicep' = {
Expand All @@ -37,8 +45,10 @@ module appServicePlan 'modules/appServicePlan.bicep' = {
sku: appServiceSkuName
capacity: capacity
kind: kind
tags: calculatedTags
}
}

module appServicePlanSettings 'modules/appServiceSettings.bicep' = if (enableAutoScale) {
name: 'appServicePlanSettingsName'
scope: resourceGroup(targetSubscriptionId_Var, targetASPResourceGroup.name)
Expand All @@ -48,5 +58,7 @@ module appServicePlanSettings 'modules/appServiceSettings.bicep' = if (enableAut
svcPlanNameID: appServicePlan.outputs.svcPlanID
}
}

output appServicePlanName string = appServicePlanName
output resourceGroupName string = targetResourceGroup
output tags object = calculatedTags
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ param location string
param capacity int = 2
param kind string
param sku string
param tags object = {}

var reserved = kind == 'linux' ? true : false

Expand All @@ -17,6 +18,7 @@ resource svcPlanName_resource 'Microsoft.Web/serverfarms@2020-12-01' = {
properties: {
reserved: reserved
}
tags: tags
}

output svcPlanName string = svcPlanName_resource.name
Expand Down
10 changes: 10 additions & 0 deletions src/bicep/examples/containerRegistry/contRegistry.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ param contRegistryName string = replace('${mlzDeploymentVariables.mlzResourcePre
@description('The name of the resource group in which the container registry will be deployed. If unchanged or not specified, the MLZ shared services resource group is used.')
param targetResourceGroup string = '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}'

@description('A string dictionary of tags to add to deployed resources. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources?tabs=json#arm-templates for valid settings.')
param tags object = {}
var defaultTags = {
'DeploymentType': 'MissionLandingZoneARM'
}
var calculatedTags = union(tags, defaultTags)

var targetSubscriptionId_Var = targetResourceGroup == '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}' ? '${mlzDeploymentVariables.spokes.Value[2].subscriptionId}' : subscription().subscriptionId
var location = deployment().location

resource targetACRResourceGroup 'Microsoft.Resources/resourceGroups@2020-10-01' = {
name: targetResourceGroup
location: location
tags: calculatedTags
}

module containerRegistry 'modules/containerRegistry.bicep' = {
scope: resourceGroup(targetSubscriptionId_Var, targetACRResourceGroup.name)
name: contRegistryName
params: {
registryName: contRegistryName
tags: calculatedTags
}
}

output azureContainerRegistryName string = contRegistryName
output azureContainerRegistryResourceGroup string = targetACRResourceGroup.name
output tags object = calculatedTags
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ param registryName string
param location string = resourceGroup().location
param registrySku string = 'premium'
param publicNetworkAccess string = 'enabled'
param tags object = {}

resource registryName_resource 'Microsoft.ContainerRegistry/registries@2020-11-01-preview' = {
name: registryName
location: location
sku: {
name: registrySku
}
tags: tags
properties: {
publicNetworkAccess: publicNetworkAccess
adminUserEnabled: true
Expand Down
2 changes: 1 addition & 1 deletion src/bicep/examples/inheritTags/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Inheriting Tags

This example adds a virtual machine adds ia policy to a given resource group that forces a specific tag to be inherited by all of its child components. This example is useful for those trying to create a charging model or provide tracking for resource consumption based on resources in a specific resource group or scope. You can use this to apply a custom tag of your choosing.
This example adds a policy to a given resource group that forces a specific tag to be inherited by all of its child components. This example is useful for those trying to create a charging model or provide tracking for resource consumption based on resources in a specific resource group or scope. You can use this to apply a custom tag of your choosing.

## What this example does

Expand Down
10 changes: 9 additions & 1 deletion src/bicep/examples/keyVault/azureKeyVault.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ param keyVaultName string = '${mlzDeploymentVariables.mlzResourcePrefix.Value}-a
@description('The name of the resource group in which the key vault will be deployed. If unchanged or not specified, the MLZ shared services resource group is used.')
param targetResourceGroup string = '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}'

@description('A string dictionary of tags to add to deployed resources. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources?tabs=json#arm-templates for valid settings.')
param tags object = {}
var defaultTags = {
'DeploymentType': 'MissionLandingZoneARM'
}
var calculatedTags = union(tags, defaultTags)

var targetSubscriptionId_Var = targetResourceGroup == '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}' ? '${mlzDeploymentVariables.spokes.Value[2].subscriptionId}' : subscription().subscriptionId
var location = deployment().location


resource targetASPResourceGroup 'Microsoft.Resources/resourceGroups@2020-10-01' = {
name: targetResourceGroup
location: location
Expand All @@ -26,8 +32,10 @@ module deployAzureKeyVault 'modules/keyVault.bicep' = {
params: {
keyVaultName: keyVaultName
tenantID: subscription().tenantId
tags: calculatedTags
}
}

output azureKeyVaultName string = keyVaultName
output resourceGroupName string = targetResourceGroup
output tags object = calculatedTags
2 changes: 2 additions & 0 deletions src/bicep/examples/keyVault/modules/keyVault.bicep
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
param keyVaultName string
param location string = resourceGroup().location
param tenantID string
param tags object = {}

resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' = {
name: keyVaultName
location: location
tags: tags
properties: {
sku: {
family: 'A'
Expand Down
25 changes: 17 additions & 8 deletions src/bicep/examples/newWorkload/newWorkload.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ param workloadName string

param resourceGroupName string = '${workloadName}-rg'
param location string = deployment().location
param tags object = {
'resourceIdentifier': resourceIdentifier
}

param hubSubscriptionId string = mlzDeploymentVariables.hub.Value.subscriptionId
param hubResourceGroupName string = mlzDeploymentVariables.hub.Value.resourceGroupName
Expand Down Expand Up @@ -49,19 +46,27 @@ param subnetServiceEndpoints array = []
param logStorageAccountName string = toLower(take('logs${uniqueString(subscription().subscriptionId, workloadName)}', 24))
param logStorageSkuName string = 'Standard_GRS'

param resourceIdentifier string = '${workloadName}${uniqueString(workloadName)}'
@description('A string dictionary of tags to add to deployed resources. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources?tabs=json#arm-templates for valid settings.')
param tags object = {}
var defaultTags = {
'DeploymentType': 'MissionLandingZoneARM'
}
var calculatedTags = union(tags, defaultTags)

resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = {
module resourceGroup '../../modules/resourceGroup.bicep' = {
name: resourceGroupName
location: location
tags: tags
params: {
name: resourceGroupName
location: location
tags: calculatedTags
}
}

module spokeNetwork '../../modules/spokeNetwork.bicep' = {
name: 'spokeNetwork'
scope: az.resourceGroup(resourceGroup.name)
params: {
tags: tags
tags: calculatedTags

logStorageAccountName: logStorageAccountName
logStorageSkuName: logStorageSkuName
Expand Down Expand Up @@ -109,7 +114,11 @@ module hubToWorkloadVirtualNetworkPeering './modules/hubNetworkPeering.bicep' =
}
}

output resourceGroupName string = resourceGroup.outputs.name
output location string = resourceGroup.outputs.location
output tags object = resourceGroup.outputs.tags
output virtualNetworkName string = spokeNetwork.outputs.virtualNetworkName
output virtualNetworkAddressPrefix string = spokeNetwork.outputs.virtualNetworkAddressPrefix
output virtualNetworkResourceId string = spokeNetwork.outputs.virtualNetworkResourceId
output subnetName string = spokeNetwork.outputs.subnetName
output subnetAddressPrefix string = spokeNetwork.outputs.subnetAddressPrefix
Expand Down
9 changes: 9 additions & 0 deletions src/bicep/examples/remoteAccess/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ param windowsVmStorageAccountType string = 'StandardSSD_LRS'

param nowUtc string = utcNow()

@description('A string dictionary of tags to add to deployed resources. See https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-resources?tabs=json#arm-templates for valid settings.')
param tags object = {}
var defaultTags = {
'DeploymentType': 'MissionLandingZoneARM'
}
var calculatedTags = union(tags, defaultTags)

module remoteAccess '../../modules/remoteAccess.bicep' = {
name: 'deploy-remoteAccess-Example-${nowUtc}'
params: {
Expand Down Expand Up @@ -102,5 +109,7 @@ module remoteAccess '../../modules/remoteAccess.bicep' = {
windowsVmStorageAccountType: windowsVmStorageAccountType

logAnalyticsWorkspaceId: logAnalyticsWorkspaceResourceId

tags: calculatedTags
}
}
Loading

0 comments on commit 88e3a45

Please sign in to comment.