Bylaw

Gallery › Network › Azure Community Policy

Adds the default network security group to subnets in case there is none.

Doesn't convert yet Policy Audit Deny Disabled Modify Mode All Version 1.0.0

Adds the default network security group to subnets in case there is none. Nothing happens when another network security group is already associated with the subnet.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 66 lines
{
  "name": "ba4a485a-81cc-426c-9813-58ef0c97edec",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Adds the default network security group to subnets in case there is none.",
    "description": "Adds the default network security group to subnets in case there is none. Nothing happens when another network security group is already associated with the subnet.",
    "metadata": {
      "category": "Network",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "networkSecurityGroupSettings": {
        "type": "Object",
        "metadata": {
          "displayName": "Network Security Group Settings",
          "description": "Location-specific settings for network security groups."
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Modify, Deny, Audit or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "Modify",
          "Deny",
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Modify"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Network/virtualNetworks/subnets"
          },
          {
            "field": "Microsoft.Network/virtualNetworks/subnets/networkSecurityGroup.id",
            "exists": "false"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
          ],
          "conflictEffect": "audit",
          "operations": [
            {
              "operation": "add",
              "field": "Microsoft.Network/virtualNetworks/subnets/networkSecurityGroup.id",
              "value": "[concat(subscription().id, '/resourceGroups/', parameters('networkSecurityGroupSettings')[field('location')].resourceGroupName, '/providers/Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupSettings')[field('location')].networkSecurityGroupName)]"
            }
          ]
        }
      }
    }
  }
}

Source: policyDefinitions/Network/adds-the-default-network-security-group-to-subnets-in-case-there-is-none/azurepolicy.json in Azure/Community-Policy, under the MIT licence.