Share via

Azure Policy to Auto Associate Resources to NSP

Tapasya Sharma 0 Reputation points Microsoft Employee
2026-03-02T18:14:59.0966667+00:00

I have a created an Azure Policy to Auto Associate Resources to NSP in Enforced mode once any new resources are created in my subscription. However, upon assigning this policy to my subscription all my resources are non-compliant, and new resources I create are not compliant by the policy either by auto-associating. I created a remediation task with and without 'ResourceDiscoveryMode' set to 'ReEvaluateCompliance. However, I continue to get this error saying there is no evaluation from the policy. Could you please help identify the issue here and correct it to auto associate any resources in enforced mode?

Expected behaviour:

Is to auto associate any new resources created to PPE NSP in enforced mode and pass compliance with existing resources by remediating.

Existing behaviour:

  1. Unable to auto associate any new resources created
  2. Unable to pass compliance even though existing resource association to NSP exists
  3. Remediation tasks fail even 'ResourceDiscoveryMode' set to 'ReEvaluateCompliance'
  4. NoPolicyEvaluationResult deployment error received

Policy definition:

  "properties": {
    "displayName": "Auto-Associate-Resources-To-NSP",
    "policyType": "Custom",
    "mode": "Indexed",
    "description": "",
    "metadata": {
      "category": "Network-Security-Perimeter",
      "createdBy": "7e4f6cdd-81b5-4b29-b6e1-dff1cea96b93",
      "createdOn": "2026-02-26T20:37:44.8507596Z",
      "updatedBy": "7e4f6cdd-81b5-4b29-b6e1-dff1cea96b93",
      "updatedOn": "2026-02-27T23:16:24.6740823Z"
    },
    "version": "1.0.0",
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "Microsoft.Storage/storageAccounts",
          "Microsoft.KeyVault/vaults",
          "Microsoft.DocumentDB/databaseAccounts"
        ]
      },
      "then": {
        "effect": "deployIfNotExists",
        "details": {
          "type": "Microsoft.Network/networkSecurityPerimeters/resourceAssociations",
          "resourceGroupName": "MOR-PME-PPE",
          "existenceCondition": {
            "allOf": [
              {
                "field": "type",
                "equals": "Microsoft.Network/networkSecurityPerimeters/resourceAssociations"
              },
              {
                "field": "name",
                "equals": "[concat('nsp-OrganizationMasterNSP-PPE/', field('name'), '_association')]"
              }
            ]
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "resourceName": {
                    "type": "string"
                  },
                  "resourceId": {
                    "type": "string"
                  },
                  "resourceType": {
                    "type": "string"
                  },
                  "baseName": {
                    "type": "string"
                  },
                  "environment": {
                    "type": "string"
                  },
                  "resourceGroup": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  }
                },
                "variables": {
                  "nspName": "[concat('nsp-', parameters('baseName'), '-', parameters('environment'))]",
                  "profileName": "[if(equals(parameters('resourceType'), 'Microsoft.Storage/storageAccounts'), 'StoragePPEProfile', if(equals(parameters('resourceType'), 'Microsoft.KeyVault/vaults'), 'KVPPEProfile', 'CosmosPPEProfile'))]",
                  "associationName": "[concat('nsp-', parameters('baseName'), '-', parameters('environment'), '/', parameters('resourceName'), '_association')]"
                },
                "resources": [
                  {
                    "type": "Microsoft.Network/networkSecurityPerimeters/resourceAssociations",
                    "apiVersion": "2024-06-01-preview",
                    "name": "[variables('associationName')]",
                    "location": "[parameters('location')]",
                    "properties": {
                      "profile": {
                        "id": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroup'), '/providers/Microsoft.Network/networkSecurityPerimeters/', variables('nspName'), '/profiles/', variables('profileName'))]"
                      },
                      "accessMode": "Enforced",
                      "privateLinkResource": {
                        "id": "[parameters('resourceId')]"
                      }
                    }
                  }
                ]
              },
              "parameters": {
                "resourceName": {
                  "value": "[field('name')]"
                },
                "resourceId": {
                  "value": "[field('id')]"
                },
                "resourceType": {
                  "value": "[field('type')]"
                },
                "baseName": {
                  "value": "OrganizationMasterNSP"
                },
                "environment": {
                  "value": "PPE"
                },
                "resourceGroup": {
                  "value": "MOR-PME-PPE"
                },
                "location": {
                  "value": "[field('location')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },

Deployment error:

User's image

Azure Policy
Azure Policy

An Azure service that is used to implement corporate governance and standards at scale for Azure resources.

{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.