Rush saves new version numbers to package.json
files, while Bicep templates are using deploy.parameters.json
to provide configuration to the templates.
We will now:
- update Bicep templates to use the versions set by rush in the Azure bicep templates and ensure provisioned resources are appropriately tagged,
- calculate new Template Spec version, based on the version changes of the Bicep templates
Update Bicep templates
⚠️ Commit and push the configuration changes to
main
, before moving on to the Bicep templates updates.
Use a new branch when following the steps described in this post; it will allow you to test the functioning ofrush change
command.
To add current template version as a tag to the Azure resources, update the *.bicep
and *.parameters.json
files.
Parameters
To tag provisioned resources with new version numbers, add new parameters for Template specs and for each Bicep template in the project.
Use version_{FOLDER_NAME}
format for parameter names for bicep template versions.
See that the versions in the file below are set to 0.0.0
, while the versions in the package.json files are 0.0.1
. That's OK, they will be soon updated by rush.
deploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "Development"
},
"project": {
"value": "MyProjectName"
},
"costCenter": {
"value": "CostCenter"
},
"webAppName": {
"value": "MyAzureFunction"
},
// --> add the following lines:
"version_ApplicationInsights": {
"value": "0.0.0"
},
"version_FunctionApp": {
"value": "0.0.0"
},
"version_TemplateSpec": {
"value": "0.0.0"
}
}
}
Bicep templates
In this sample project, all resources already have tags. Update the deploy.bicep
file to tag all resources with the Template Spec version, and append resource's version to the resources' tags.
AzureTemplates\deploy.bicep
param costCenter string
param environment string
param project string
param version_TemplateSpec string // <-- Add this line
param version_ApplicationInsights string // <-- Add this line
param version_FunctionApp string // <-- Add this line
param webAppName string
var tags = {
Environment: environment
CostCenter: costCenter
Project: project
TemplateSpec_Solution: version_TemplateSpec // <-- Add this line
}
module deployAppInsights 'ApplicationInsights/ApplicationInsights.bicep' = {
name: 'ApplicationInsights'
params: {
applicationInsightsName: 'ApplicationInsightsRushIaC'
// --> Use union to append resource tag
tags: union(tags, {
version: version_ApplicationInsights
})
appInsightsLocation: resourceGroup().location
}
}
module deploy 'FunctionApp/FunctionApp.bicep' = {
name: 'FunctionApp'
dependsOn: [deployAppInsights]
params: {
appName: webAppName
// --> Use union to append resource tag
tags: union(tags, {
version: version_FunctionApp
})
location: resourceGroup().location
applicationInsightsName: 'ApplicationInsightsRushIaC'
}
}
Custom commands
Rush may be extended with additional capabilities using custom commands.
Run rush update
to create a common\scripts
folder. Copy the following files into the scripts
folder:
The rush-TemplateSpec.js
script retrieves version numbers from parameters.json
file of each "project" managed by rush, and saves them to the corresponding parameter in the AzureTemplates/deploy.parameters.json
file. If needed, the version_TemplateSpec
version number is updated to reflect the changes in the Bicep resources.
To register the script as a custom command replace the contents of the common\config\rush\command-line.json
with the following:
common\config\rush\command-line.json
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json",
"commands": [
{
"name": "ver:azure",
"commandKind": "global",
"summary": "Analyzes versions of rush-managed projects and bumps TemplateSpec versions",
"shellCommand": "node common/scripts/rush-TemplateSpec.js"
}
],
"parameters": [
{
"parameterKind": "string",
"argumentName": "POLICY",
"longName": "--version-policy",
"shortName": "-p",
"description": "Version policy name. Only projects with this version policy will be published if used with --include-all.",
"associatedCommands": [
"ver:azure"
]
}
]
}
Test
Rung rush ver:azure --version-policy AzTemplateSpecs
to copy the versions of the resources into the corresponding parameter in the azuredeploy.parameters.json
file.
The script print information about how many changes of each type (major/minor/patch) have been found, and how the version of the Template Spec has been altered:
The deploy.parameters.json
file is now updated accordingly.
The process of creating new release would therefore look as follows:
# increase versions and create changelogs
rush version --bump
# copy version numbers to Bicep parameters file and
# set TemplateSpec version to be used by PowerShell script
rush ver:azure --version-policy AzTemplateSpecs
💡 Since Template Specs don't have Bicep templates and are instead created with Azure CLI, there will be no automatic version updates or changelog generation for Template Specs with rush.
Instead, you may update the rush-TemplateSpec.js to generate your own changelog.json and changelog.md for Template Specs.
Next step: Deployment
Top comments (0)