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/governance/policy/assign-policy-terraform.md
+35-37Lines changed: 35 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
---
2
2
title: "Quickstart: New policy assignment with Terraform"
3
-
description: In this quickstart, you use Terraform and HCL syntax to create a policy assignment to identify non-compliant resources.
4
-
ms.date: 03/01/2023
3
+
description: In this quickstart, you use Terraform and Hashicorp Configuration Language (HCL) syntax to create a policy assignment to identify non-compliant resources.
4
+
ms.date: 03/25/2024
5
5
ms.topic: quickstart
6
6
ms.custom: devx-track-terraform
7
7
ms.tool: terraform
8
8
---
9
+
9
10
# Quickstart: Create a policy assignment to identify non-compliant resources using Terraform
10
11
11
12
The first step in understanding compliance in Azure is to identify the status of your resources.
12
13
This quickstart steps you through the process of creating a policy assignment to identify virtual
13
14
machines that aren't using managed disks.
14
15
15
-
At the end of this process, you'll successfully identify virtual machines that aren't using managed
16
-
disks across subscription. They're _non-compliant_ with the policy assignment.
16
+
At the end of this process, you identify virtual machines that aren't using managed disks across subscription. They're _non-compliant_ with the policy assignment.
17
17
18
18
## Prerequisites
19
19
@@ -28,17 +28,14 @@ disks across subscription. They're _non-compliant_ with the policy assignment.
28
28
29
29
## Create the Terraform configuration, variable, and output file
30
30
31
-
In this quickstart, you create a policy assignment and assign the **Audit VMs that do not use
32
-
managed disks** (`06a78e20-9358-41c9-923c-fb736d382a4d`) definition. This policy definition
33
-
identifies resources that aren't compliant to the conditions set in the policy definition.
31
+
In this quickstart, you create a policy assignment and assign the [Audit VMs that do not use managed disks](https://github.com/Azure/azure-policy/blob/master/built-in-policies/policyDefinitions/Compute/VMRequireManagedDisk_Audit.json) definition. This policy definition identifies resources that aren't compliant to the conditions set in the policy definition.
34
32
35
-
First, configure the Terraform configuration, variable, and output files. The Terraform resources
Configure the Terraform configuration, variable, and output files. The Terraform resources
34
+
for Azure Policy use the [Azure Provider](https://www.terraform.io/docs/providers/azurerm/index.html).
38
35
39
36
1. Create a new folder named `policy-assignment` and change directories into it.
40
37
41
-
2. Create `main.tf` with the following code:
38
+
1. Create `main.tf` with the following code:
42
39
43
40
> [!NOTE]
44
41
> 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.
:::image type="content" source="./media/assign-policy-terraform/terraform-apply.png" alt-text="Screenshot of running the terraform apply command and the resulting resource creation.":::
137
135
138
-
With the "Apply complete! Resources: 1 added, 0 changed, 0 destroyed." message, the policy
136
+
With the `Apply complete! Resources: 1 added, 0 changed, 0 destroyed.` message, the policy
139
137
assignment is now created. Since we defined the `outputs.tf` file, the _assignment\_id_ is also
140
138
returned.
141
139
@@ -153,25 +151,25 @@ Your results resemble the following example:
0 commit comments