Project: environment-based infrastructure¶
Goal: deploy consistent building blocks with separate environment inputs without copying entire templates.
Components and expected result¶
The project composes a VNet, private-only storage account and container,
Log Analytics workspace, and user-assigned managed identity.
Names derive from a prefix/environment and deterministic uniqueness.
The prod sample changes log retention, not the architecture's availability.
flowchart TD
Inputs["dev or prod parameter file"] --> Root["Environment main.bicep"]
Root --> Network["VNet"]
Root --> Storage["Private storage + container"]
Root --> Logs["Log Analytics"]
Root --> Identity["Managed identity"]
Source and input file¶
@description('Organization or workload naming prefix.')
@minLength(2)
@maxLength(12)
param prefix string
@description('Deployment environment.')
@allowed(['dev', 'test', 'prod'])
param environment string
@description('Azure region.')
param location string = resourceGroup().location
var suffix = uniqueString(resourceGroup().id, prefix, environment)
var tags = { environment: environment, managedBy: 'bicep' }
module network '../../0_core-infrastructure/virtual-network/main.bicep' = {
name: 'network'
params: { name: '${prefix}-${environment}-vnet', location: location, tags: tags }
}
module storage '../../1_storage-databases/storage-account/main.bicep' = {
name: 'storage'
params: { name: 'st${suffix}', location: location, containers: ['documents'], coolAfterDays: 30 }
}
module monitoring '../../6_monitoring-management/log-analytics/main.bicep' = {
name: 'monitoring'
params: { name: '${prefix}-${environment}-logs', location: location, retentionDays: environment == 'prod' ? 90 : 30 }
}
module identity '../../4_identity-security/managed-identity/main.bicep' = {
name: 'identity'
params: { name: '${prefix}-${environment}-identity', location: location }
}
output networkId string = network.outputs.id
output storageId string = storage.outputs.id
output workspaceId string = monitoring.outputs.id
output principalId string = identity.outputs.principalId
using './main.bicep'
param prefix = 'learn'
param environment = 'dev'
param location = 'eastus2'
Compile first¶
az bicep build --file 13_projects/environment-foundation/main.bicep --stdout
az bicep build-params --file 13_projects/environment-foundation/dev.bicepparam --stdout
Optional deployment¶
Use your own *.local.bicepparam when regional or organization settings differ.
Create a dedicated resource group for each environment and review scope before
running these Bash commands:
az deployment group what-if --resource-group "$RG" \
--parameters 13_projects/environment-foundation/dev.bicepparam
az deployment group create --resource-group "$RG" \
--parameters 13_projects/environment-foundation/dev.bicepparam
az resource list --resource-group "$RG" --output table
Expected: four infrastructure building blocks and a private blob container. No application data connection is ready: add appropriate endpoints, DNS, and data roles as a follow-on exercise. Verify that dev and prod use separate groups, different names, and the intended retention.
Cleanup and extension¶
After inspecting the dedicated group, use az group delete --name "$RG".
Retained resources and logs can cost money before deletion completes.
See the catalog module README for more detail.
Extension: add a private endpoint and role assignment through modules. Explain why the project still needs a network-connected test client.