Exercise - Assign and test an Azure Policy
This guided project consists of the following exercises:
- Apply cost-tracking tags
- Create budget and alerts
- Assign and test Azure Policy
In this exercise, you assign an Azure Policy that restricts resource creation to a specific region, test that it blocks a noncompliant deployment, and review the compliance dashboard. This demonstrates how policy enforcement prevents mistakes before they happen.
This exercise includes the following tasks:
- Find and assign the policy
- Validate policy enforcement
- Review policy compliance
Outcome: A policy control is assigned and validated by a simple compliance test.
Task 1: Find and assign the policy
Use Azure Policy to enforce organizational standards. Policies can deny noncompliant resource creation automatically, preventing costly mistakes before they happen.
- In the portal search bar, search for Policy and select Policy.
- In the left menu, select Definitions.
- In the search box, search for Allowed locations.
- Select the Allowed locations policy definition.
- Select Assign.
- For Scope, select your resource group rg-gp-cost-guardrails.
- On the Parameters tab, select one region as the allowed location (for example, your home region).
- Select Review + create and then select Create.
Note
Validation step: Confirm the Allowed locations policy is assigned to rg-gp-cost-guardrails.
Task 2: Validate policy enforcement
Test that the policy prevents resource creation in disallowed regions. This validation confirms that your governance control is working correctly and would protect against noncompliant deployments.
- In the portal search bar, search for Storage accounts and select Storage accounts.
- Select + Create.
- On the Basics tab, select rg-gp-cost-guardrails as the resource group.
- For Storage account name, enter a temporary name (for example, stgppolicytest followed by your initials).
- For Region, select a region that is not the allowed location you configured in the policy.
- Select Review + create.
- Confirm the creation is denied with a policy error message. Note the error—it references the Allowed locations policy by name.
- Select Previous to return to the Basics tab.
- Change the Region to the allowed location.
- Select Review + create again.
- Confirm the validation passes.
- Select Create.
Note
Validation step: Confirm the policy denied creation in the disallowed region and allowed it in the permitted region.
Task 3: Review policy compliance
Check the policy compliance dashboard to see how Azure tracks compliance across your resources. This is where administrators monitor whether organizational standards are being followed.
- In the portal search bar, search for Policy and select Policy.
- In the left menu, select Compliance.
- Find the Allowed locations policy assignment in the compliance list.
- Select it to view the compliance details, including the number of compliant and noncompliant resources.
- Note the compliance state—resources created in the allowed region should show as compliant.
Note
Validation step: Confirm the Compliance dashboard shows the policy enforcement status with compliant resources in the allowed region.