You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/essentials/diagnostics-settings-policies-deployifnotexists.md
+46-37Lines changed: 46 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,7 @@ Policies and policy initiatives provide a simple method to enable logging at-sca
15
15
Enable resource logs to track activities and events that take place on your resources and give you visibility and insights into any changes that occur.
16
16
Assign policies to enable resource logs and to send them to destinations according to your needs. Send logs to Event Hubs for third-party SIEM systems, enabling continuous security operations. Send logs to storage accounts for longer term storage or the fulfillment of regulatory compliance.
17
17
18
-
A set of built-in policies and initiatives exists to direct resource logs to Log Analytics Workspaces, Event Hubs, and Storage Accounts.
19
-
20
-
The policies enable audit logging, sending logs belonging to the **audit** log category group to an Event Hub, Log Analytics workspace or Storage Account.
21
-
22
-
The policies' `effect` is `DeployIfNotExists`, which deploys the policy as a default if there aren't other settings defined.
18
+
A set of built-in policies and initiatives exists to direct resource logs to Log Analytics Workspaces, Event Hubs, and Storage Accounts. The policies enable audit logging, sending logs belonging to the **audit** log category group to an Event Hub, Log Analytics workspace or Storage Account. The policies' `effect` is `DeployIfNotExists`, which deploys the policy as a default if there aren't other settings defined.
23
19
24
20
25
21
## Deploy policies.
@@ -52,50 +48,54 @@ The policy visible in the resources' diagnostic setting after approximately 30 m
52
48
### [CLI](#tab/cli)
53
49
To apply a policy using the CLI, use the following commands:
For example, to apply the policy to send audit logs to a log analytics workspace
51
+
1. Create a policy assignment using [`az policy assignment create`](https://learn.microsoft.com/cli/azure/policy/assignment?view=azure-cli-latest#az-policy-assignment-create).
az policy assignment identity assign --system-assigned -g <resource group name> --role <role name or ID> --identity-scope </scope> -n <policy assignment name>
80
-
```
81
-
For example:
71
+
```
72
+
Assign the required role using [`az policy assignment identity assign`](https://learn.microsoft.com/cli/azure/policy/assignment/identity?view=azure-cli-latest):
73
+
```azurecli
74
+
az policy assignment identity assign --system-assigned --resource-group <resource group name> --role <role name or ID> --identity-scope </scope> --name <policy assignment name>
1. Trigger a scan to find existing resources using [`az policy state trigger-scan`](https://learn.microsoft.com/cli/azure/policy/state?view=azure-cli-latest#az-policy-state-trigger-scan).
az policy state trigger-scan --resource-group rg-001
84
+
```
86
85
87
-
3. Create a remediation task to apply the policy to existing resources.
86
+
1. Create a remediation task to apply the policy to existing resources using [`az policy remediation create`](https://learn.microsoft.com/cli/azure/policy/remediation?view=azure-cli-latest#az-policy-remediation-create).
88
87
89
-
```azurecli
90
-
az policy remediation create -g <resource group name> --policy-assignment <policy assignment name> --name <remediation name>
91
-
```
88
+
```azurecli
89
+
az policy remediation create -g <resource group name> --policy-assignment <policy assignment name> --name <remediation name>
90
+
```
92
91
93
-
For example,
94
-
```azurecli
95
-
az policy remediation create -g rg-001 -n remediation-001 --policy-assignment policy-assignment-1
96
-
```
92
+
For example,
93
+
```azurecli
94
+
az policy remediation create -g rg-001 -n remediation-001 --policy-assignment policy-assignment-1
95
+
```
97
96
98
97
For more information on policy assignment using CLI, see [Azure CLI reference - az policy assignment](https://learn.microsoft.com/cli/azure/policy/assignment?view=azure-cli-latest#az-policy-assignment-create)
98
+
99
99
### [PowerShell](#tab/Powershell)
100
100
101
101
To apply a policy using the PowerShell, use the following commands:
@@ -222,20 +222,24 @@ Change the default name in the **Parameters** tab of the **Assign initiative** o
@@ -271,9 +278,10 @@ You can get your policy assignment details using the following command:
271
278
272
279
273
280
1. Sign in to your Azure account using the `az login` command.
274
-
1. Select the subscription where you want to apply the policy initiative using the `az account` set command.
281
+
1.
282
+
1. Select the subscription where you want to apply the policy initiative using the `az account set` command.
275
283
276
-
1. Assign the initiative using [az policy assignment create](https://learn.microsoft.com/cli/azure/policy/assignment?view=azure-cli-latest#az-policy-assignment-create).
284
+
1. Assign the initiative using [`az policy assignment create`](https://learn.microsoft.com/cli/azure/policy/assignment?view=azure-cli-latest#az-policy-assignment-create).
277
285
278
286
```azurecli
279
287
az policy assignment create --name <assignment name> --resource-group <resource group name> --policy-set-definition <initiative name> --params <parameters object> --mi-system-assigned --location <location>
@@ -295,7 +303,7 @@ You can get your policy assignment details using the following command:
295
303
"deployment": {
296
304
"properties": {...
297
305
```
298
-
Assign the required role using [az policy assignment identity assign](https://learn.microsoft.com/cli/azure/policy/assignment/identity?view=azure-cli-latest):
306
+
Assign the required role using [`az policy assignment identity assign`](https://learn.microsoft.com/cli/azure/policy/assignment/identity?view=azure-cli-latest):
299
307
```azurecli
300
308
az policy assignment identity assign --system-assigned --resource-group <resource group name> --role <role name or ID> --identity-scope <scope> --name <policy assignment name>
301
309
```
@@ -304,13 +312,14 @@ You can get your policy assignment details using the following command:
1. Create remediation tasks for the policies in the initiative.
308
317
309
318
Remediation tasks are created per-policy. Each task is for a specific `definition-reference-id`, specified in the initiative as `policyDefinitionReferenceId`. To find the `definition-reference-id` parameter, use the following command:
310
319
```azurecli
311
320
az policy set-definition show --name f5b29bc4-feca-4cc6-a58a-772dd5e290a5 |grep policyDefinitionReferenceId
312
321
```
313
-
Remediate the resources using [az policy remediation create](https://learn.microsoft.com/cli/azure/policy/remediation?view=azure-cli-latest#az-policy-remediati
322
+
Remediate the resources using [`az policy remediation create`]https://learn.microsoft.com/cli/azure/policy/remediation?view=azure-cli-latest#az-policy-remediation-create)
314
323
315
324
```azurecli
316
325
az policy remediation create --resource-group <resource group name> --policy-assignment <assignment name> --name <remediation task name> --definition-reference-id "policy specific reference ID" --resource-discovery-mode ReEvaluateCompliance
0 commit comments