Sunday, September 4, 2022

Structure for Azure Policy as a Code using Bicep

Following is the structure for code to write Azure Policy as a Code. You can specify policy initiatives, definitions and assignments as you wish



//Parameters
//Variables

//Policy initiative
resource PolicyInitiative 'Microsoft.Authorization/policySetDefinitions@2020-09-01' = {
  properties: {
    policyType: 'Custom'
    displayName: initiativeName
    description: 'Custom Policy Initiative'
    metadata: {
      category: policyCategory
      source: policySource
      version: '0.1.0'
    }
    parameters: {
      //Your custom parameters
    }
    policyDefinitions: [    
      //Selected policy definitions based on existing Microsoft policy definitions  
    ]
  }
}

//Policy assignment
resource PolicyAssignment 'Microsoft.Authorization/policyAssignments@2020-09-01' = {
  name: assignmentName
  properties: {
    displayName: assignmentName
    description: 'Custom Policy Assignment'
    enforcementMode: assignmentEnforcementMode
    metadata: {
      source: policySource
      version: '0.1.0'
    }
    policyDefinitionId: PolicyInitiative.id
    parameters: {
      //Your parameters
    }
  }
}

No comments: