Bylaw

Gallery › General › Azure Community Policy

require-resource-location-match-resourceGroup

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

need to add description

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

Azure Policy JSONazurepolicy.json · 49 lines
{
  "name": "e32e7ef8-047c-45d7-9a7a-a494ae29e975",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "require-resource-location-match-resourceGroup",
    "description": "need to add description",
    "metadata": {
      "version": "1.0.0",
      "category": "General"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "location",
            "notEquals": "[resourceGroup().location]"
          },
          {
            "field": "location",
            "notEquals": "global"
          },
          {
            "field": "type",
            "notEquals": "Microsoft.AzureActiveDirectory/b2cDirectories"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylawe32e7ef8-047c-45d7-9a7a-a494ae29e975.bylaw.ps1 · 32 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'e32e7ef8-047c-45d7-9a7a-a494ae29e975' {

    Properties @{
        DisplayName = 'require-resource-location-match-resourceGroup'
        Description = 'need to add description'
        Version     = '1.0.0'
        Category    = 'General'
        Mode        = 'Indexed'
    }

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

    Resource * {

        When {
            Field location | Must -Not -Be (Arm '[resourceGroup().location]')
            Field location | Must -Not -Be 'global'
        }

        Require 'type is Microsoft.AzureActiveDirectory/b2cDirectories' {
            Field type | Must -Be 'Microsoft.AzureActiveDirectory/b2cDirectories'
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/General/require-resource-location-match-resourcegroup/azurepolicy.json in Azure/Community-Policy, under the MIT licence.