-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
4533f73
commit 44118b9
Showing
5 changed files
with
245 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
tests/PSRule.Rules.Azure.Tests/Template.Policy.WithDeployment.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"policyName": { | ||
"metadata": { | ||
"description": "Policy name" | ||
}, | ||
"type": "string", | ||
"defaultValue": "Policy-example" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"name": "[parameters('policyName')]", | ||
"type": "Microsoft.Authorization/policyDefinitions", | ||
"apiVersion": "2021-06-01", | ||
"properties": { | ||
"policyType": "Custom", | ||
"mode": "Indexed", | ||
"displayName": "Deploy a route table with specific user defined routes", | ||
"description": "Deploys a route table with specific user defined routes when one does not exist. The route table deployed by the policy must be manually associated to subnet(s)", | ||
"metadata": { | ||
"version": "1.0.0", | ||
"category": "Network", | ||
"source": "https://github.com/Azure/Enterprise-Scale/", | ||
"alzCloudEnvironments": [ | ||
"AzureCloud", | ||
"AzureChinaCloud", | ||
"AzureUSGovernment" | ||
] | ||
}, | ||
"parameters": { | ||
"effect": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "Effect", | ||
"description": "Enable or disable the execution of the policy" | ||
}, | ||
"allowedValues": [ | ||
"DeployIfNotExists", | ||
"Disabled" | ||
], | ||
"defaultValue": "DeployIfNotExists" | ||
}, | ||
"requiredRoutes": { | ||
"type": "Array", | ||
"metadata": { | ||
"displayName": "requiredRoutes", | ||
"description": "Routes that must exist in compliant route tables deployed by this policy" | ||
} | ||
}, | ||
"vnetRegion": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "vnetRegion", | ||
"description": "Only VNets in this region will be evaluated against this policy" | ||
} | ||
}, | ||
"routeTableName": { | ||
"type": "String", | ||
"metadata": { | ||
"displayName": "routeTableName", | ||
"description": "Name of the route table automatically deployed by this policy" | ||
} | ||
}, | ||
"disableBgpPropagation": { | ||
"type": "Boolean", | ||
"metadata": { | ||
"displayName": "DisableBgpPropagation", | ||
"description": "Disable BGP Propagation" | ||
}, | ||
"defaultValue": false | ||
} | ||
}, | ||
"policyRule": { | ||
"if": { | ||
"allOf": [ | ||
{ | ||
"field": "type", | ||
"equals": "Microsoft.Network/virtualNetworks" | ||
}, | ||
{ | ||
"field": "location", | ||
"equals": "[[parameters('vnetRegion')]" | ||
} | ||
] | ||
}, | ||
"then": { | ||
"effect": "[[parameters('effect')]", | ||
"details": { | ||
"type": "Microsoft.Network/routeTables", | ||
"existenceCondition": { | ||
"allOf": [ | ||
{ | ||
"field": "name", | ||
"equals": "[[parameters('routeTableName')]" | ||
}, | ||
{ | ||
"count": { | ||
"field": "Microsoft.Network/routeTables/routes[*]", | ||
"where": { | ||
"value": "[[concat(current('Microsoft.Network/routeTables/routes[*].addressPrefix'), ';', current('Microsoft.Network/routeTables/routes[*].nextHopType'), if(equals(toLower(current('Microsoft.Network/routeTables/routes[*].nextHopType')),'virtualappliance'), concat(';', current('Microsoft.Network/routeTables/routes[*].nextHopIpAddress')), ''))]", | ||
"in": "[[parameters('requiredRoutes')]" | ||
} | ||
}, | ||
"equals": "[[length(parameters('requiredRoutes'))]" | ||
} | ||
] | ||
}, | ||
"roleDefinitionIds": [ | ||
"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-0000-000000000000" | ||
], | ||
"deployment": { | ||
"properties": { | ||
"mode": "incremental", | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"routeTableName": { | ||
"type": "string" | ||
}, | ||
"vnetRegion": { | ||
"type": "string" | ||
}, | ||
"requiredRoutes": { | ||
"type": "array" | ||
}, | ||
"disableBgpPropagation": { | ||
"type": "bool" | ||
} | ||
}, | ||
"variables": { | ||
"copyLoop": [ | ||
{ | ||
"name": "routes", | ||
"count": "[[[length(parameters('requiredRoutes'))]", | ||
"input": { | ||
"name": "[[[concat('route-',copyIndex('routes'))]", | ||
"properties": { | ||
"addressPrefix": "[[[split(parameters('requiredRoutes')[copyIndex('routes')], ';')[0]]", | ||
"nextHopType": "[[[split(parameters('requiredRoutes')[copyIndex('routes')], ';')[1]]", | ||
"nextHopIpAddress": "[[[if(equals(toLower(split(parameters('requiredRoutes')[copyIndex('routes')], ';')[1]),'virtualappliance'),split(parameters('requiredRoutes')[copyIndex('routes')], ';')[2], null())]" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Resources/deployments", | ||
"apiVersion": "2021-04-01", | ||
"name": "routeTableDepl", | ||
"properties": { | ||
"mode": "Incremental", | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"routeTableName": { | ||
"type": "string" | ||
}, | ||
"vnetRegion": { | ||
"type": "string" | ||
}, | ||
"requiredRoutes": { | ||
"type": "array" | ||
}, | ||
"disableBgpPropagation": { | ||
"type": "bool" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.Network/routeTables", | ||
"apiVersion": "2021-02-01", | ||
"name": "[[[parameters('routeTableName')]", | ||
"location": "[[[parameters('vnetRegion')]", | ||
"properties": { | ||
"disableBgpRoutePropagation": "[[[parameters('disableBgpPropagation')]", | ||
"copy": "[[variables('copyLoop')]" | ||
} | ||
} | ||
] | ||
}, | ||
"parameters": { | ||
"routeTableName": { | ||
"value": "[[parameters('routeTableName')]" | ||
}, | ||
"vnetRegion": { | ||
"value": "[[parameters('vnetRegion')]" | ||
}, | ||
"requiredRoutes": { | ||
"value": "[[parameters('requiredRoutes')]" | ||
}, | ||
"disableBgpPropagation": { | ||
"value": "[[parameters('disableBgpPropagation')]" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"parameters": { | ||
"routeTableName": { | ||
"value": "[[parameters('routeTableName')]" | ||
}, | ||
"vnetRegion": { | ||
"value": "[[parameters('vnetRegion')]" | ||
}, | ||
"requiredRoutes": { | ||
"value": "[[parameters('requiredRoutes')]" | ||
}, | ||
"disableBgpPropagation": { | ||
"value": "[[parameters('disableBgpPropagation')]" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters