ResourceModules
ResourceModules copied to clipboard
[Feature Request]: Introduce hidden tags to store module name and version
Description
Benefit
Tags with hidden- prefix are not visible in the Azure portal except in the JSON view. by adding the additional hidden tags for CARML module names and versions allows customers to:
- Collect internal usage and inventory data for the consumption of the module. When a module requires update, customers can easily find out which resources need to be updated using simple Azure Resource Graph (ARG) queries.
- Provides the ability to control the usage of
-prereleasemodule versions being deployed outside of testing environments using Azure Policy
I am happy to raise PR to implement this feature since @ahmadabdalla and I have already developed this feature in a customer's environment.
How to implement
I have implemented this feature in a customer's environment. here's what I did:
- update the pipeline tasks to write the full
major.minor.patchversion number to the version.json in the run time, before the module publishing step. - update each CARML module to add the module name and version. version number is extracted from
version.jsonfile:
var moduleVersion = loadJsonContent('./version.json').version
var mergedTags = union(tags, {
'hidden-module_name': 'storage/storage-account'
'hidden-module_version': moduleVersion
})
- Pass the
mergedTagsto thetagsproperty of the resources
How to consume the hidden module name and version tags
Collecting internal usage telemetry data
Here are some sample ARG queries:
Get all Overlay module usage
resources
| where tags['hidden-module_name'] matches regex '.'
| summarize count() by type
Get all Key Vaults deployed using Overlay module and show version
resources
| where type =~ "microsoft.keyvault/vaults"
| where tags['hidden-module_name'] =~ 'key-vault/vault'
| project name, tags
| mvexpand tags
| extend tagKey = tostring(bag_keys(tags)[0])
| extend tagValue = tostring(tags[tagKey])
| distinct name, tagKey, tagValue
| where tagKey =~ "hidden-module_version"
| project KeyVaultName = name, OverlayModuleVersion = tagValue
Restrict resources to be deployed using prerelease overlay module versions
Here's a sample policy definition I have created to restrict the use of `-prerelease' versions:
{
"name": "pol-restrict-prerelease-overlay-module-versions",
"properties": {
"displayName": "Restrict resources to be deployed using prerelease overlay module versions",
"description": "Prerelease module versions are published for testing purposes only. They are not intended for production use and they have not gone through code review and validation. This policy restricts resources from being deployed using prerelease overlay module versions.",
"metadata": {
"category": "Code Vulnerability",
"version": "1.0.0",
"preview": false,
"depreciated": false
},
"mode": "Indexed",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Deny"
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "tags[hidden-module_version]",
"exists": true
},
{
"field": "tags[hidden-module_version]",
"like": "*-prerelease"
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}