Bylaw

Gallery › General › Azure built-in policies

Do Not Allow MCPP resources

Uses Condition Policy Audit Deny Disabled Mode All Version 1.0.0

Block creation of MCPP resources.

ConvertTo-Bylaw converted this policy, and proved it compiles back to the same definition. Conditions the language can't express yet are written as raw JSON with Condition.

Azure Policy JSONNotAllowMCPP_Deny.json · 52 lines
{
  "properties": {
    "displayName": "Do Not Allow MCPP resources",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Block creation of MCPP resources.",
    "metadata": {
      "version": "1.0.0",
      "category": "General"
    },
    "Version": "1.0.0",
    "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": "type",
            "in": [
              "Microsoft.CloudPartnerProgram/memberships"
            ]
          },
          {
            "value": "[field('type')]",
            "exists": true
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/335d919a-dc24-4a94-b7cb-9f81b1a8156f",
  "name": "335d919a-dc24-4a94-b7cb-9f81b1a8156f"
}
Bylaw335d919a-dc24-4a94-b7cb-9f81b1a8156f.bylaw.ps1 · 32 lines
# Converted from NotAllowMCPP_Deny.json by ConvertTo-Bylaw.
Policy '335d919a-dc24-4a94-b7cb-9f81b1a8156f' {

    Properties @{
        DisplayName   = 'Do Not Allow MCPP resources'
        Description   = 'Block creation of MCPP resources.'
        Version       = '1.0.0'
        Category      = 'General'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        When {
            Field type | Must -BeIn @('Microsoft.CloudPartnerProgram/memberships')
        }

        Require 'type is as required' {
            Condition -Violation '{ "value": "[field(''type'')]", "exists": true }'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/General/NotAllowMCPP_Deny.json in Azure/azure-policy, under the MIT licence.