Skip to content

Commit a34f02b

Browse files
(AzureCXP) fixes MicrosoftDocs/azure-docs#103542
1 parent 044eb7a commit a34f02b

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

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

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,57 +37,55 @@ for Azure Policy use the
3737

3838
1. Create a new folder named `policy-assignment` and change directories into it.
3939

40-
1. Create `main.tf` with the following code:
40+
2. Create `main.tf` with the following code:
4141

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.
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.
4444
4545

46-
```terraform
47-
provider "azurerm" {
48-
features {}
46+
```terraform
47+
provider "azurerm" {
48+
features {}
49+
}
50+
51+
terraform {
52+
required_providers {
53+
azurerm = {
54+
source = "hashicorp/azurerm"
55+
version = ">= 2.96.0"
56+
}
57+
}
58+
}
59+
60+
resource "azurerm_subscription_policy_assignment" "auditvms" {
61+
name = "audit-vm-manageddisks"
62+
subscription_id = var.cust_scope
63+
policy_definition_id = "/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a4d"
64+
description = "Shows all virtual machines not using managed disks"
65+
display_name = "Audit VMs without managed disks assignment"
66+
}
67+
```
68+
3. Create `variables.tf` with the following code:
69+
70+
```terraform
71+
variable "cust_scope" {
72+
default = "{scope}"
4973
}
74+
```
5075
51-
terraform {
52-
required_providers {
53-
azurerm = {
54-
source = "hashicorp/azurerm"
55-
version = ">= 2.96.0"
56-
}
57-
}
58-
}
59-
60-
resource "azurerm_subscription_policy_assignment" "auditvms" {
61-
name = "audit-vm-manageddisks"
62-
subscription_id = var.cust_scope
63-
policy_definition_id = "/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a4d"
64-
description = "Shows all virtual machines not using managed disks"
65-
display_name = "Audit VMs without managed disks assignment"
66-
}
67-
```
68-
1. Create `variables.tf` with the following code:
69-
70-
```terraform
71-
variable "cust_scope" {
72-
default = "{scope}"
73-
}
74-
```
75-
76-
A scope determines what resources or grouping of resources the policy assignment gets enforced
77-
on. It could range from a management group to an individual resource. Be sure to replace
78-
`{scope}` with one of the following patterns based on the declared resource:
76+
A scope determines what resources or grouping of resources the policy assignment gets enforced on. It could range from a management group to an individual resource. Be sure to replace `{scope}` with one of the following patterns based on the declared resource:
7977
8078
- Subscription: `/subscriptions/{subscriptionId}`
8179
- Resource group: `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}`
8280
- Resource: `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]`
8381
84-
1. Create `output.tf` with the following code:
82+
4. Create `output.tf` with the following code:
8583
86-
```terraform
87-
output "assignment_id" {
88-
value = azurerm_resource_policy_assignment.auditvms.id
89-
}
90-
```
84+
```terraform
85+
output "assignment_id" {
86+
value = azurerm_resource_policy_assignment.auditvms.id
87+
}
88+
```
9189
9290
## Initialize Terraform and create plan
9391

0 commit comments

Comments
 (0)