Skip to content

Commit 161f3a3

Browse files
(AzureCXP) fixes MicrosoftDocs/azure-docs#103542
1 parent 0051797 commit 161f3a3

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

articles/governance/policy/assign-policy-terraform.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This quickstart steps you through the process of creating a policy assignment to
1212
machines that aren't using managed disks.
1313

1414
At the end of this process, you'll successfully identify virtual machines that aren't using managed
15-
disks. They're _non-compliant_ with the policy assignment.
15+
disks across subscription. They're _non-compliant_ with the policy assignment.
1616

1717
## Prerequisites
1818

@@ -38,6 +38,10 @@ for Azure Policy use the
3838
1. Create a new folder named `policy-assignment` and change directories into it.
3939

4040
1. Create `main.tf` with the following code:
41+
42+
> [!NOTE]
43+
> To create a Policy Assignment at a Management Group use the [azurerm_management_group_policy_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_group_policy_assignment) resource, for a Resource Group use the [azurerm_resource_group_policy_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group_policy_assignment) and for a Subscription use the [azurerm_subscription_policy_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subscription_policy_assignment) resource.
44+
4145

4246
```hcl
4347
provider "azurerm" {
@@ -53,9 +57,9 @@ for Azure Policy use the
5357
}
5458
}
5559

56-
resource "azurerm_resource_policy_assignment" "auditvms" {
60+
resource "azurerm_subscription_policy_assignment" "auditvms" {
5761
name = "audit-vm-manageddisks"
58-
resource_id = var.cust_scope
62+
subscription_id = var.cust_scope
5963
policy_definition_id = "/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a4d"
6064
description = "Shows all virtual machines not using managed disks"
6165
display_name = "Audit VMs without managed disks assignment"
@@ -72,7 +76,7 @@ for Azure Policy use the
7276

7377
A scope determines what resources or grouping of resources the policy assignment gets enforced
7478
on. It could range from a management group to an individual resource. Be sure to replace
75-
`{scope}` with one of the following patterns:
79+
`{scope}` with one of the following patterns based on the declared resource:
7680

7781
- Subscription: `/subscriptions/{subscriptionId}`
7882
- Resource group: `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}`
@@ -144,7 +148,7 @@ returned by `terraform apply`. With it, run the following command to get the res
144148
non-compliant resources that are output into a JSON file:
145149

146150
```console
147-
armclient post "/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01&$filter=IsCompliant eq false and PolicyAssignmentId eq '<policyAssignmentID>'&$apply=groupby((ResourceId))" > <json file to direct the output with the resource IDs into>
151+
armclient post "/subscriptions/<subscriptionID>/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01&$filter=IsCompliant eq false and PolicyAssignmentId eq '<policyAssignmentID>'&$apply=groupby((ResourceId))" > <json file to direct the output with the resource IDs into>
148152
```
149153

150154
Your results resemble the following example:

0 commit comments

Comments
 (0)