Skip to content

Commit

Permalink
Merge pull request #189 from ElYusubov/development
Browse files Browse the repository at this point in the history
Standardized the policy assignment in bicep code
  • Loading branch information
ElYusubov authored Nov 6, 2024
2 parents 31f8515 + 5785008 commit 6add417
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion tagging-policies/audit-resource-tag.bicep
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// audit-resource-tag.bicep

// Set the scope of the deployment
targetScope = 'subscription'

// Set variables for the policy definition
var policyName = 'audit-resource-tag-pd'
var policyDisplayName = 'Audit a tag on resources'
var policyDescription = 'Audits existence of a tag. Does not apply to resource groups.'

// Create the policy definition
resource policy 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {
name: policyName
properties: {
Expand All @@ -24,7 +29,6 @@ resource policy 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {
}
}
}

policyRule: {
if: {
field: '[concat(\'tags[\', parameters(\'tagName\'), \']\')]'
Expand All @@ -36,3 +40,21 @@ resource policy 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {
}
}
}

// Create the policy assignment
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2020-09-01' = {
name: '${policyName}-assignment'
properties: {
policyDefinitionId: policy.id
displayName: policyDisplayName
description: policyDescription
parameters: {
tagName: {
value: 'Environment'
}
tagPattern: {
value: 'Test'
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resource policy 'Microsoft.Authorization/policyDefinitions@2020-09-01' = {

// Create the policy assignment
resource policyAssignment 'Microsoft.Authorization/policyAssignments@2020-09-01' = {
name: '${policyName}-pa'
name: '${policyName}-assignment'
properties: {
policyDefinitionId: policy.id
displayName: policyDisplayName
Expand Down

0 comments on commit 6add417

Please sign in to comment.