Bylaw

Gallery › Network › Azure Community Policy

Deploy route to route tables

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

This policy deploys a route to a route tables.

ConvertTo-Bylaw can't convert this policy yet:

Azure Policy JSONazurepolicy.json · 142 lines
{
  "name": "38a35686-0bab-4939-98bb-e417a9019ba5",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Deploy route to route tables",
    "description": "This policy deploys a route to a route tables.",
    "metadata": {
      "category": "Network",
      "createdBy": "",
      "updatedBy": null,
      "updatedOn": null,
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "addressPrefix": {
        "type": "string",
        "metadata": {
          "description": "The destination IP address range in CIDR notation that this Policy checks for within the UDR. Example: 0.0.0.0/0 to check for the presence of a default route.",
          "displayName": "Address Prefix"
        }
      },
      "nextHopIpAddress": {
        "type": "string",
        "metadata": {
          "description": "The IP address packets should be forwarded to.",
          "displayName": "Next Hop IP Address"
        }
      },
      "nextHopType": {
        "type": "string",
        "metadata": {
          "description": "The next hope type that the policy checks for within the inspected route. The value can be Virtual Network, Virtual Network Gateway, Internet, Virtual Appliance, or None.",
          "displayName": "Next Hop Type"
        },
        "allowedValues": [
          "VnetLocal",
          "VirtualNetworkGateway",
          "Internet",
          "VirtualAppliance",
          "None"
        ]
      },
      "routename": {
        "type": "string",
        "metadata": {
          "description": "The name of the route.",
          "displayName": "Route Name"
        }
      },
      "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": [
          {
            "equals": "Microsoft.Network/routeTables",
            "field": "type"
          },
          {
            "count": {
              "field": "Microsoft.Network/routeTables/routes[*]",
              "where": {
                "allOf": [
                  {
                    "equals": "[parameters('addressPrefix')]",
                    "field": "Microsoft.Network/routeTables/routes[*].addressPrefix"
                  },
                  {
                    "equals": "[parameters('nextHopType')]",
                    "field": "Microsoft.Network/routeTables/routes[*].nextHopType"
                  },
                  {
                    "equals": "[parameters('nextHopIpAddress')]",
                    "field": "Microsoft.Network/routeTables/routes[*].nextHopIpAddress"
                  }
                ]
              }
            },
            "equals": 0
          },
          {
            "allOf": [
              {
                "equals": "0.0.0.0/0",
                "value": "[parameters('addressPrefix')]"
              },
              {
                "count": {
                  "field": "Microsoft.Network/routeTables/subnets[*]",
                  "where": {
                    "field": "Microsoft.Network/routeTables/subnets[*].name",
                    "in": [
                      "GatewaySubnet"
                    ]
                  }
                },
                "equals": 0
              }
            ]
          }
        ]
      },
      "then": {
        "details": {
          "conflictEffect": "deny",
          "operations": [
            {
              "field": "Microsoft.Network/routeTables/routes[*]",
              "operation": "add",
              "value": {
                "name": "[parameters('routename')]",
                "properties": {
                  "addressPrefix": "[parameters('addressPrefix')]",
                  "nextHopIpAddress": "[parameters('nextHopIpAddress')]",
                  "nextHopType": "[parameters('nextHopType')]"
                }
              }
            }
          ],
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/4d97b98b-1d4f-4787-a291-c67834d212e7"
          ]
        },
        "effect": "[parameters('effect')]"
      }
    }
  }
}

Source: policyDefinitions/Network/deploy-route-to-route-tables/azurepolicy.json in Azure/Community-Policy, under the MIT licence.