Azure 2: Resource Groups & Subscriptions
easy⏱ 5 mincourseazure
Azure Resource Hierarchy
Azure organizes resources in a tree: Management Groups (top-level containers for multiple subscriptions) > Subscriptions (billing boundary, linked to an Azure account) > Resource Groups (logical container for related resources) > Resources (VMs, databases, storage accounts, etc.). Every resource must belong to exactly one resource group, and every resource group to one subscription.
// Azure CLI: Create a resource group
az group create \
--name myResourceGroup \
--location eastus
// List all resource groups
az group list --output table
Model the resource hierarchy
Create a function createSubscription that takes name: string and returns an object with name, id (generate with sub- prefix), and a resourceGroups array. Add a method addResourceGroup that takes a group name and returns the group object with a resources array. Log the subscription name.
Naming conventions matter
Use consistent naming: rg- prefix for resource groups, vm- for VMs, st for storage accounts, kv- for Key Vaults. Example: rg-webapp-prod-eastus. This makes resources instantly identifiable in the portal and CLI output.
Quiz: Resource Group Rules
Can a resource belong to multiple resource groups? No — a resource belongs to exactly one resource group. However, resources in different groups can communicate with each other. Deleting a resource group deletes ALL resources inside it.