Existing Resources and Data
What You'll Learn
You'll learn how to reference Azure resources that already exist in your subscription and retrieve their properties from within Bicep templates.
The Core Idea
Not every deployment starts from scratch. Often, you need to interact with resources that were created previously—perhaps a virtual network from another team, a key vault from a prior project, or a storage account deployed last year. Bicep's existing keyword lets you reference these already-deployed resources without trying to create them again.
Think of it like looking up a contact in your phone instead of adding a new one. You're not creating a new entry; you're simply retrieving information about someone who's already there.
How It Works
Use the existing keyword in a resource declaration, along with the resource's name:
resource existingVnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
name: 'my-existing-vnet'
}
Once referenced, you can access properties:
output vnetId string = existingVnet.id
output addressSpace array = existingVnet.properties.addressSpace.addressPrefixes
You can also reference resources in different resource groups by specifying scope:
resource existingKeyVault 'Microsoft.KeyVault/vaults@2021-06-01' existing = {
name: 'shared-keyvault'
scope: resourceGroup('shared-rg')
}
This is invaluable when building infrastructure that depends on shared resources, centralizing networking, or integrating with existing environments without managing their lifecycle.
Use Cases
- Retrieving subnet IDs from a centrally managed virtual network
- Reading connection strings from an existing database
- Getting endpoints from a shared storage account
- Cross-referencing resources managed by other teams
Key Takeaway: The existing keyword allows you to read and reference already-deployed Azure resources in your Bicep templates without managing their creation or lifecycle.