Hands-On Lab845 words

Lab: Implementing Azure Governance and Compliance

Describe features and tools in Azure for governance and compliance

Lab: Implementing Azure Governance and Compliance

This hands-on lab guides you through the practical application of Azure's primary governance tools: Azure Policy, Resource Locks, and Resource Tags. These tools ensure that resources remain compliant with organizational standards and are protected from accidental changes.

[!WARNING] Remember to run the teardown commands at the end of this lab to avoid ongoing charges and to clean up your environment.

Prerequisites

  • An active Azure Subscription (Free Trial is sufficient).
  • Azure CLI installed locally or access to Azure Cloud Shell.
  • Permissions to create Resource Groups and assign Policies (Owner or Contributor role).

Learning Objectives

  1. Enforce Compliance: Create and assign an Azure Policy to restrict resource locations.
  2. Prevent Accidental Deletion: Apply a CanNotDelete Resource Lock to a critical resource.
  3. Organize Resources: Implement a tagging strategy for cost tracking and management.
  4. Verify Governance: Use the Azure CLI and Portal to validate that restrictions are active.

Architecture Overview

The following diagram illustrates the hierarchy where governance tools are applied in this lab:

Loading Diagram...

Step-by-Step Instructions

Step 1: Create a Resource Group

Before applying governance, we need a container for our resources.

bash
az group create --name "brainybee-gov-lab" --location "eastus"
Console alternative
  1. Search for Resource groups in the Azure Portal.
  2. Click + Create.
  3. Select your subscription.
  4. Name it brainybee-gov-lab and select East US.
  5. Click Review + create and then Create.

Step 2: Apply a Resource Lock

Resource locks prevent accidental deletion or modification of critical resources. We will apply a CanNotDelete lock to our new group.

bash
az lock create --name "LockGroup" --resource-group "brainybee-gov-lab" --lock-type "CanNotDelete" --notes "Prevent accidental deletion of the governance lab."

[!TIP] Even an Owner of the subscription cannot delete a resource until this lock is manually removed first.

Console alternative
  1. Open your resource group brainybee-gov-lab.
  2. On the left menu, scroll to Settings and select Locks.
  3. Click + Add.
  4. Name: LockGroup, Lock type: Delete.
  5. Click OK.

Step 3: Assign an Azure Policy

Azure Policy enforces rules. We will assign a policy that only allows resources to be created in specific regions (e.g., East US and West US).

bash
# Assign the 'Allowed Locations' policy az policy assignment create --name "Restrict-Locations" \ --policy "e56962a6-4747-49cd-b67b-bf8b01975a4c" \ --params "{'listOfAllowedLocations': {'value': ['eastus', 'westus']}}" \ --resource-group "brainybee-gov-lab"
Console alternative
  1. Search for Policy in the Azure Portal.
  2. Select Assignments > Assign policy.
  3. Scope: Select brainybee-gov-lab.
  4. Policy definition: Search for Allowed locations.
  5. Under Parameters, uncheck "Only show parameters that need input" and select East US and West US.
  6. Click Review + create > Create.

Step 4: Apply Resource Tags

Tags are key-value pairs used for metadata. We'll tag the resource group for cost center tracking.

bash
az group update --name "brainybee-gov-lab" --set tags.Dept=Finance tags.Project=Governance

Checkpoints

CheckActionExpected Result
Verify LockAttempt to delete the group: az group delete --name "brainybee-gov-lab"Error: The scope is locked and cannot be deleted.
Verify PolicyAttempt to create a storage account in ukwest: az storage account create -n brainybeetest -g brainybee-gov-lab -l ukwest --sku Standard_LRSError: Request disallowed by policy.
Verify TagsView tags: az group show --name "brainybee-gov-lab" --query tagsOutput shows Dept: Finance and Project: Governance.

Troubleshooting

ErrorCauseFix
AuthorizationFailedInsufficient permissions to assign policies.Ensure you have 'Owner' or 'User Access Administrator' roles.
ScopeLockedTrying to delete/move a resource with a lock.Remove the lock from the 'Locks' blade in the portal before deleting.
PolicyViolationTrying to deploy in a region not in your 'Allowed' list.Change the deployment location to 'eastus' or update the policy params.

Clean-Up / Teardown

To delete the resources, you must first remove the lock.

  1. Remove the lock:
bash
az lock delete --name "LockGroup" --resource-group "brainybee-gov-lab"
  1. Delete the resource group:
bash
az group delete --name "brainybee-gov-lab" --yes --no-wait

Concept Review

Understanding the hierarchy of Azure Governance tools is essential for the AZ-900 exam:

\begin{tikzpicture}[node distance=1.5cm, every node/.style={draw, fill=blue!10, rounded corners, minimum width=3cm}] \node (MG) {Management Groups}; \node (SUB) [below of=MG] {Subscriptions}; \node (RG) [below of=SUB] {Resource Groups}; \node (RES) [below of=RG] {Resources};

code
\draw[->] (MG) -- (SUB); \draw[->] (SUB) -- (RG); \draw[->] (RG) -- (RES); \node[draw=none, fill=none, right=2cm of RG, text width=4cm] (note) {\small \textbf{Governance Applied:}\\ - Policies\\ - Locks\\ - Tags\\ - RBAC};

\end{tikzpicture}

ToolPrimary PurposeReal-World Example
Azure PolicyEnforce standards / ComplianceDisallowing the creation of expensive G-series VMs.
Resource LocksData protection / SafetyLocking a Production Database from being deleted.
TagsTaxonomy / BillingTagging resources with Environment: Production for cost split.
Microsoft PurviewData GovernanceMapping sensitive data across SQL and Blob storage.

Ready to study Microsoft Azure Fundamentals (AZ-900)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free