Bylaw

Gallery › General › Azure built-in policies

Allowed resource types

Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0

This policy enables you to specify the resource types that your organization can deploy. Only resource types that support 'tags' and 'location' will be affected by this policy. To restrict all resources please duplicate this policy and change the 'mode' to 'All'.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONAllowedResourceTypes_Deny.json · 53 lines
{
  "properties": {
    "displayName": "Allowed resource types",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "This policy enables you to specify the resource types that your organization can deploy. Only resource types that support 'tags' and 'location' will be affected by this policy. To restrict all resources please duplicate this policy and change the 'mode' to 'All'.",
    "metadata": {
      "version": "1.1.0",
      "category": "General"
    },
    "version": "1.1.0",
    "parameters": {
      "listOfResourceTypesAllowed": {
        "type": "Array",
        "metadata": {
          "description": "The list of resource types that can be deployed.",
          "displayName": "Allowed resource types",
          "strongType": "resourceTypes"
        }
      },
      "effect": {
        "type": "String",
        "defaultValue": "Deny",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "not": {
          "field": "type",
          "in": "[parameters('listOfResourceTypesAllowed')]"
        }
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.1.0",
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c",
  "name": "a08ec900-254a-4555-9bf5-e42af04b5c5c"
}
Bylawa08ec900-254a-4555-9bf5-e42af04b5c5c.bylaw.ps1 · 34 lines
# Converted from AllowedResourceTypes_Deny.json by ConvertTo-Bylaw.
Policy 'a08ec900-254a-4555-9bf5-e42af04b5c5c' {

    Properties @{
        DisplayName   = 'Allowed resource types'
        Description   = 'This policy enables you to specify the resource types that your organization can deploy. Only resource types that support ''tags'' and ''location'' will be affected by this policy. To restrict all resources please duplicate this policy and change the ''mode'' to ''All''.'
        Version       = '1.1.0'
        Category      = 'General'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter ListOfResourceTypesAllowed @{
        Type        = 'Array'
        DisplayName = 'Allowed resource types'
        Description = 'The list of resource types that can be deployed.'
        Metadata    = [ordered]@{ strongType = 'resourceTypes' }
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type is one of the ListOfResourceTypesAllowed parameter' {
            Field type | Must -BeIn (Param ListOfResourceTypesAllowed)
        }
    }

    Effect (Param Effect)
}

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