Skip to content

Resource declarations and reusable modules

Resource anatomy

A declaration has a symbolic name, provider/type/API version, deployed name, and provider-defined properties. Symbolic names connect resources in code; deployed names must meet Azure naming rules. A child resource can use parent instead of duplicating its full type/name expression.

Private DNS module
@description('Service private DNS zone, such as privatelink.vaultcore.azure.net.')
param name string
@description('Existing virtual network resource ID.')
param virtualNetworkId string

resource zone 'Microsoft.Network/privateDnsZones@2020-06-01' = {
  name: name
  location: 'global'
}
resource link 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = {
  parent: zone
  name: 'client-network'
  location: 'global'
  properties: {
    registrationEnabled: false
    virtualNetwork: { id: virtualNetworkId }
  }
}

output id string = zone.id

The VNet link depends on the zone through parent. An existing declaration, as used by the subnet module, references rather than creates a resource. It still needs a correct scope and name.

Module composition

Private web architecture
@description('Globally unique web app name; also used as a naming prefix.')
param name string
@description('Azure region.')
param location string = resourceGroup().location

module network '../../0_core-infrastructure/virtual-network/main.bicep' = {
  name: 'network'
  params: { name: '${name}-vnet', location: location }
}
module subnet '../../0_core-infrastructure/subnet/main.bicep' = {
  name: 'endpoint-subnet'
  params: { name: 'endpoints', virtualNetworkName: network.outputs.name, addressPrefix: '10.20.1.0/24' }
}
module web '../../2_compute-containers/app-service/main.bicep' = {
  name: 'web'
  params: { name: name, location: location }
}
module dns '../../3_networking/private-dns/main.bicep' = {
  name: 'dns'
  params: { name: 'privatelink.azurewebsites.net', virtualNetworkId: network.outputs.id }
}
module endpoint '../../3_networking/private-endpoint/main.bicep' = {
  name: 'endpoint'
  params: {
    name: '${name}-pe'
    location: location
    subnetId: subnet.outputs.id
    targetResourceId: web.outputs.id
    groupId: 'sites'
    privateDnsZoneId: dns.outputs.id
  }
}

output hostname string = web.outputs.hostname
output appId string = web.outputs.id

A module is another Bicep file deployed with inputs. Passing web.outputs.id to the endpoint establishes a dependency. Do not add a redundant dependsOn when a resource/output reference already expresses it.

Ownership and scope

Choose one owner for each resource. Do not mix inline subnet definitions and separate subnet modules without understanding redeployment behavior. Separate environment/resource-group boundaries from module boundaries. Modules default to their parent's scope; cross-resource-group and subscription deployments need an explicit scope supported by that module.

RBAC is not networking

Managed identity creation does not grant access. A role assignment does not create private DNS. A private endpoint does not authorize an application. Model all three deliberately and test from the intended runtime.

Exercise: trace the secure-web dependency chain from VNet to subnet to private endpoint. Explain why App Service creation can run alongside VNet creation, but the endpoint cannot.