Multi-tier network segmentation¶
Level: Advanced
Overview and purpose¶
Compose web, application, and data subnets with individual NSGs and explicit tier-to-tier TCP paths.
Azure services and dependencies¶
Read main.bicep for the exact resource types, supported API versions, decorators, and outputs. No secret values are required or emitted by this module.
Prerequisites¶
Install Azure CLI and Bicep, authenticate to the intended subscription, and
confirm az account show before executing cloud commands.
Plan the 10.40.0.0/16 range and understand the sample ports: 443, 8443, and 5432.
Use the repository root as the working directory. Commands below use Bash
(Azure Cloud Shell works); PowerShell variable syntax differs.
Set RG to a dedicated existing sandbox group (except for the subscription-scoped
resource-group example), and LOCATION to an approved Azure region.
Set shell variables PREFIX to your own approved values.
For array/object inputs, put valid JSON in the corresponding quoted variable.
Never use example IDs as real principal/resource IDs.
Important parameters¶
| Parameter | Type | Requirement |
|---|---|---|
prefix |
string |
Required |
location |
string |
Optional; see source default |
Descriptions and defaults live beside each declaration in the canonical source. Names must meet the individual Azure service's naming rules.
Bicep source and usage¶
View the complete source.
Reference this module from another Bicep file with a relative module path and
a params object. The resources/modules lesson shows composition and dependencies.
Compile and validate locally¶
az bicep build --file 12_architecture-examples/multi-tier/main.bicep --stdout
Compilation and linting need no Azure login and create no resources. A successful compile is not evidence that a deployment or application has been tested.
Deployment instructions¶
These are opt-in cloud operations, never routine CI steps. Review policy, permissions, region, quotas, dependencies, and price before proceeding.
az deployment group validate --resource-group "$RG" --template-file 12_architecture-examples/multi-tier/main.bicep --parameters prefix="$PREFIX"
az deployment group what-if --resource-group "$RG" --template-file 12_architecture-examples/multi-tier/main.bicep --parameters prefix="$PREFIX"
az deployment group create --resource-group "$RG" --template-file 12_architecture-examples/multi-tier/main.bicep --parameters prefix="$PREFIX"
For a reusable deployment, put your own values into an untracked
*.local.bicepparam file with a using declaration instead of embedding
environment identifiers into the module.
Expected results and validation¶
The deployment returns the outputs declared at the end of main.bicep.
Inspect the deployment's provisioning state and resource IDs in Azure Portal
or Azure CLI. For a resource-group deployment:
az resource list --resource-group "$RG" --output table
For subscription resource-group creation, verify az group show --name "$NAME".
Then perform the service-specific checks below. No live Azure deployment is
claimed by this repository's offline CI.
Service-specific checks and limitations¶
This is a network pattern, not a complete running three-tier application. Replace sample ports/prefixes with your design and validate effective NSG rules.
Cleanup¶
Only if this is a dedicated disposable group, inspect its contents and delete it:
az resource list --resource-group "$RG" --output table
az group delete --name "$RG"
For the resource-group module use the created NAME as RG.
Do not delete shared prerequisites or groups containing unrelated work.
Deletion can be delayed by locks, soft-delete, protection settings, or backup
retention. Verify completion in Azure; stopping compute is not full cleanup.
Cost and security considerations¶
The VNet/NSG foundation has no direct compute charge. No application, database, load balancer, or public access is deployed.
Use least privilege and approved regions. Consult the current Azure pricing calculator and Microsoft Bicep resource reference.
Complete Bicep source¶
@description('Short naming prefix.')
param prefix string
@description('Azure region.')
param location string = resourceGroup().location
module network '../../0_core-infrastructure/virtual-network/main.bicep' = {
name: 'network'
params: { name: '${prefix}-vnet', location: location, addressPrefixes: ['10.40.0.0/16'] }
}
var tiers = [
{ name: 'web', prefix: '10.40.1.0/24', source: '10.40.1.0/24', port: '443' }
{ name: 'application', prefix: '10.40.2.0/24', source: '10.40.1.0/24', port: '8443' }
{ name: 'data', prefix: '10.40.3.0/24', source: '10.40.2.0/24', port: '5432' }
]
module groups '../../0_core-infrastructure/network-security-group/main.bicep' = [for tier in tiers: {
name: '${tier.name}-nsg'
params: {
name: '${prefix}-${tier.name}-nsg'
location: location
securityRules: [
{
name: 'AllowTier'
properties: {
priority: 100
direction: 'Inbound'
access: 'Allow'
protocol: 'Tcp'
sourcePortRange: '*'
destinationPortRange: tier.port
sourceAddressPrefix: tier.source
destinationAddressPrefix: tier.prefix
}
}
{
name: 'DenyOtherInbound'
properties: {
priority: 4096
direction: 'Inbound'
access: 'Deny'
protocol: '*'
sourcePortRange: '*'
destinationPortRange: '*'
sourceAddressPrefix: '*'
destinationAddressPrefix: '*'
}
}
]
}
}]
@batchSize(1)
module subnets '../../0_core-infrastructure/subnet/main.bicep' = [for (tier, index) in tiers: {
name: '${tier.name}-subnet'
params: {
name: tier.name
virtualNetworkName: network.outputs.name
addressPrefix: tier.prefix
networkSecurityGroupId: groups[index].outputs.id
}
}]
output subnetIds array = [for (_, index) in tiers: subnets[index].outputs.id]