Gallery › General › Azure Community Policy
Name pattern with like condition.
Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0
Enforce a naming pattern on resources with the like condition.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 45 lines
{
"name": "84af5e9f-aeed-4e1d-b901-f3a595fc67d7",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Name pattern with like condition.",
"description": "Enforce a naming pattern on resources with the like condition.",
"metadata": {
"version": "1.0.0",
"category": "General"
},
"mode": "Indexed",
"parameters": {
"namePattern": {
"type": "String",
"metadata": {
"description": "Pattern to use for names. Can include wildcard (*)."
}
},
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Deny, Audit or Disabled the execution of the Policy"
},
"allowedValues": [
"Deny",
"Audit",
"Disabled"
],
"defaultValue": "Audit"
}
},
"policyRule": {
"if": {
"not": {
"field": "name",
"like": "[parameters('namePattern')]"
}
},
"then": {
"effect": "[parameters('effect')]"
}
}
}
}Bylaw84af5e9f-aeed-4e1d-b901-f3a595fc67d7.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '84af5e9f-aeed-4e1d-b901-f3a595fc67d7' {
Properties @{
DisplayName = 'Name pattern with like condition.'
Description = 'Enforce a naming pattern on resources with the like condition.'
Version = '1.0.0'
Category = 'General'
Mode = 'Indexed'
}
Parameter NamePattern @{
Type = 'String'
Description = 'Pattern to use for names. Can include wildcard (*).'
}
Parameter Effect @{
AllowedValues = @('Deny', 'Audit', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Deny, Audit or Disabled the execution of the Policy'
}
Resource * {
Require 'name is like the NamePattern parameter' {
Field name | Must -BeLike (Param NamePattern)
}
}
Effect (Param Effect)
}Source: policyDefinitions/General/name-pattern-with-like-condition/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw