Training
Module
Deploy child and extension resources by using Bicep - Training
Learn how to deploy child and extension resources, and refer to existing resources, within your Bicep code.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
To reference an existing resource that isn't deployed in your current Bicep file, declare the resource with the existing
keyword. Use the existing
keyword when you're deploying a resource that needs to get a value from an existing resource. You access the existing resource's properties through its symbolic name.
The resource isn't redeployed when referenced with the existing
keyword.
The following example gets an existing storage account in the same resource group as the current deployment. Notice that you provide only the name of the existing resource. The properties are available through the symbolic name.
resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' existing = {
name: 'examplestorage'
}
output blobEndpoint string = stg.properties.primaryEndpoints.blob
Set the scope
property to access a resource in a different scope. The following example references an existing storage account in a different resource group.
resource stg 'Microsoft.Storage/storageAccounts@2023-04-01' existing = {
name: 'examplestorage'
scope: resourceGroup(exampleRG)
}
output blobEndpoint string = stg.properties.primaryEndpoints.blob
For more information about setting the scope, see Scope functions for Bicep.
If you attempt to reference a resource that doesn't exist, you get the NotFound
error and your deployment fails. Check the name and scope of the resource you're trying to reference.
For the syntax to deploy a resource, see Resource declaration in Bicep.
Training
Module
Deploy child and extension resources by using Bicep - Training
Learn how to deploy child and extension resources, and refer to existing resources, within your Bicep code.
Documentation
Bicep functions - scopes - Azure Resource Manager
Describes the functions to use in a Bicep file to retrieve values about deployment scopes.
Conditional deployment with Bicep - Azure Resource Manager
Describes how to conditionally deploy a resource in Bicep.
Outputs in Bicep - Azure Resource Manager
Describes how to define output values in Bicep