Hello there!
I am trying to automate the deployment of Sentinel alongside connectors, however I'm having hard time for Azure activity for the policy assignment part.
The issue is when I want to define the scope to the root management groups level instead of a subscription, based on what I am trying to write I will either an error saying there is no policy in Microsoft.Authorization (The resource type could not be found in the namespace 'Microsoft.Authorization' for api version '2023-04-01'. (Code:InvalidResourceType))or:
Code=InvalidTemplateDeployment; Message=The template deployment failed with error: 'Authorization failed for template resource 'PolicyAssignment' of type 'Microsoft.Resources/deployments'. The client '[email protected]' with object id '162ea20a-121b-42f3-ab55-2a0c0df9d102' does not have permission to perform action 'Microsoft.Resources/deployments/write' at scope '/providers/Microsoft.Resources/deployments/PolicyAssignment'.'.
I'm honestly out of idea, you can find what I wrote bellow (I tried many things, none worked):
@description('Assign policy for Azure Activity')
param policyAssignmentName string = 'Test-EntraID-logs-to-LAW'
param policyDefinitionID string = '/providers/Microsoft.Authorization/policyDefinitions/2465583e-4e78-4c15-b6be-a36cbc7c8b0f'
param policyDisplayName string = 'TEST03 Configure Azure Activity logs to stream to specified Log Analytics workspace'
@description('Name for the Log Analytics workspace used to aggregate data')
param workspaceName string
resource assignment 'Microsoft.Authorization/policyAssignments@2023-04-01' = {
name: policyAssignmentName
scope: tenant()
identity: {
type: 'SystemAssigned'
}
properties: {
policyDefinitionId: policyDefinitionID
description: 'Policy assignment to resource group scope created with Bicep file'
displayName: policyDisplayName
nonComplianceMessages: [
{
message: 'Non compliant.'
}
]
parameters: {
logAnalytics: {
value: workspaceName
}
effect: {
value: 'DeployIfNotExists'
}
logsEnabled: {
value: 'True'
}
}
}
}
resource remediateTask 'Microsoft.PolicyInsights/remediations@2021-10-01' = {
name: guid('Remediate', policyDefinitionID, subscription().id)
scope: tenant()
properties: {
failureThreshold: {
percentage: 1
}
resourceCount: 500
policyAssignmentId: assignment.id
parallelDeployments: 10
resourceDiscoveryMode: 'ExistingNonCompliant'
}
}```
Thanks!