I am trying to create a Azure policy definition but getting error. This JSON code is taken from a built-in script from Azure policy "IP Forwarding on your virtual machine should be disabled" Below is my script
$Policy=
'{
"properties": {
"displayName": "Disable-IP-Forwarding",
"policyType": "Custom",
"mode": "All",
"description": "Disable-IP-Forwarding-Test.",
"metadata": {
"version": "1.0.1",
"category": "Security Center"
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "AuditIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"in": [
"Microsoft.Compute/virtualMachines",
"Microsoft.ClassicCompute/virtualMachines"
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Security/complianceResults",
"name": "disableIPForwarding",
"existenceCondition": {
"field": "Microsoft.Security/complianceResults/resourceStatus",
"in": [
"Monitored",
"OffByPolicy",
"Healthy"
]
}
}
}
}
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/Disable-IP-Forwarding",
"type": "Microsoft.Authorization/policyDefinitions",
"name": "Disable-IP-Forwarding"
}'
$definition = New-AzPolicyDefinition -Name "Disable-IP-Forwarding" -Description "Disable-IP-Forwarding-Test." -Policy $Policy
Below are the pictures from Powershell showing error.1 & 2
https://i.stack.imgur.com/Ttj4w.png https://i.stack.imgur.com/K0JCv.png
I also tried with removing single quotes in policy rule as in here(click Here)
**Error: After removing Single quote **
New-AzPolicyDefinition : InvalidPolicyRule : Failed to parse policy rule: 'Could not find member 'properties' on object of type 'PolicyRuleDefinition'. Path 'properties'.'. CorrelationId: 7e754d56-2e8e-4323-8650-ae620bb60573 At line:70 char:15
- ... efinition = New-AzPolicyDefinition -Name "Disable-IP-Forwarding" ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : CloseError: (:) [New-AzPolicyDefinition], ErrorResponseMessageException
- FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet