Azure schema and resource scope
Resource groups organize lifecycle, not network traffic
A subscription contains resource groups; a group contains related ARM resources. A group has a location for its own metadata, but resources in it can use other supported locations. Choose the group to reflect lifecycle and ownership, not merely a naming convention. A group is a useful access scope but is not a network boundary. Deleting a group can remove the resources within it; check all owners, dependencies, locks and retention before any such operation. This chapter uses a fictional catalog development group and a virtual network without deploying anything.
# Static AzureRM fragment; requires the provider configuration above.resource "azurerm_resource_group" "lab" { name = "rg-catalog-dev" location = "westeurope"}resource "azurerm_virtual_network" "lab" { name = "vnet-catalog-dev" resource_group_name = azurerm_resource_group.lab.name location = azurerm_resource_group.lab.location address_space = ["10.60.0.0/16"]}resource "azurerm_subnet" "app" { name = "app" resource_group_name = azurerm_resource_group.lab.name virtual_network_name = azurerm_virtual_network.lab.name address_prefixes = ["10.60.10.0/24"]}The references create an implicit dependency from the network to the group and from the subnet to the network. The subnet is part of the virtual network’s address space. Here 10.60.10.0/24 is contained in 10.60.0.0/16. This fragment does not configure a firewall, VM, DNS or routing policy; a successful resource plan would not prove network security or application reachability.
Read a resource ID from left to right
An ARM resource ID encodes scope and type. For this nested subnet, the path names the subscription, resource group, Microsoft.Network namespace, virtual network and child subnet. Other resources may be tenant-, subscription- or extension-scoped and have different paths. Terraform’s address azurerm_subnet.app is a local configuration/state identity, not this remote identifier. In an actual project prefer the resource’s computed ID rather than building arbitrary paths by hand.
/subscriptions/22222222-2222-2222-2222-222222222222/resourceGroups/rg-catalog-dev/providers/Microsoft.Network/virtualNetworks/vnet-catalog-dev/subnets/appUse the included provider-free local fixture to practice string interpolation without Azure. Its expected output is the ID above; this is a string construction exercise, not evidence that the resource exists.
terraform { required_version = "= 1.14.8"}locals { subscription_id = "22222222-2222-2222-2222-222222222222" group_name = "rg-catalog-dev" network_name = "vnet-catalog-dev" group_id = "/subscriptions/${local.subscription_id}/resourceGroups/${local.group_name}" network_id = "${local.group_id}/providers/Microsoft.Network/virtualNetworks/${local.network_name}" subnet_id = "${local.network_id}/subnets/app"}output "illustrative_subnet_id" { value = local.subnet_id}Inspect the schema and assign a single owner
Required arguments, optional arguments and computed attributes come from the provider schema. The network’s address_space and subnet’s address_prefixes are different inputs; the subnet’s parent name is a reference. A data source can observe a group owned elsewhere rather than declare another managed resource.
# Alternative to managing the shared resource group; not a second owner.data "azurerm_resource_group" "shared" { name = "rg-shared-dev"}output "shared_group_id" { value = data.azurerm_resource_group.shared.id}This alternative assumes the group exists and the identity can read it; the lookup can contact Azure. Do not mix standalone subnet management with inline subnet blocks for the same network. After auditing the provider binary and offline mirror, an authorized isolated authoring environment can inspect the schema with terraform providers schema -json. The command may load plugins; do not run it against an unknown directory. Schema metadata alone cannot confirm permissions, service availability, quotas or every replacement rule. Check the exact release docs and plan.
Compare Terraform with native ARM and Bicep
Bicep is an Azure-native declarative authoring language compiled into ARM deployment templates. Terraform uses provider plugins and its state mapping to track managed objects. Both can declare a virtual network, but their deployment and lifecycle mechanisms differ. Select one lifecycle owner for the network; neither an ARM deployment nor a Terraform import is automatically safe against another writer.
// Alternative ownership model; illustrative, do not deploy.targetScope = 'resourceGroup'param location string = resourceGroup().locationresource catalogNetwork 'Microsoft.Network/virtualNetworks@2024-05-01' = { name: 'vnet-catalog-dev' location: location properties: { addressSpace: { addressPrefixes: ['10.60.0.0/16'] } }}The API version is an illustrative explicit selection, not verified against a live subscription or compiled here. This fragment assumes a resource-group deployment scope. Do not deploy it alongside the Terraform fragment for the same named network.
Offline tests and a plan-review checklist
The staged native mock example checks a single planned argument. Mocking replaces provider behavior for the test but still needs the provider schema from a reviewed plugin. It cannot certify Azure API acceptance, registration, identity, network connectivity or region availability.
# Static test illustration for the network configuration.mock_provider "azurerm" {}run "network_contract" { command = plan assert { condition = azurerm_subnet.app.address_prefixes == tolist(["10.60.10.0/24"]) error_message = "The app subnet must retain its planned prefix." }}Review target tenant and subscription, namespace registration, exact provider versions, single resource ownership and network ranges. Block unexplained replacements or deletions. The core practice uses synthetic JSON and independent Python checks only; no cloud requests, mock execution or Terraform CLI tests have been run. The next chapter builds on these boundaries to design complete Azure architectures.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Azure schema and resource scope — knowledge check
Review Azure provider selection, scope and identity.
Which value is a Terraform resource address?
What creates the subnet dependency on the VNet in the example?
Who should manage a VNet already owned by a different team?
Which subnet is contained in 10.60.0.0/16 and does not overlap 10.60.10.0/24?
What does a passing mock assertion establish?