Customize Azure resources
When working with Azure integrations in Aspire, you often need to customize the provisioned infrastructure beyond the default settings. The same customization patterns apply across Azure hosting integrations such as Storage, Service Bus, Key Vault, user-assigned identities, Azure Container Apps, and Azure App Service. This page documents all customization APIs supported across both C# and TypeScript AppHost projects.
For target-specific generated resource customization, see Deploy to Azure Container Apps and Deploy to Azure App Service.
Shared Azure customization patterns
Section titled “Shared Azure customization patterns”Use existing Azure resources
Section titled “Use existing Azure resources”Use AsExisting, RunAsExisting, and PublishAsExisting when you want Aspire to reference an Azure resource that already exists instead of provisioning a new one.
var builder = DistributedApplication.CreateBuilder(args);
var existingBusName = builder.AddParameter("existingServiceBusName");var existingBusResourceGroup = builder.AddParameter("existingServiceBusResourceGroup");
var serviceBus = builder.AddAzureServiceBus("messaging") .PublishAsExisting(existingBusName, existingBusResourceGroup);
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const existingBusName: ParameterResource
existingBusName = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("existingServiceBusName");const const existingBusResourceGroup: ParameterResource
existingBusResourceGroup = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("existingServiceBusResourceGroup");
const const serviceBus: AzureServiceBusResource
serviceBus = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureServiceBus(name: string): AzureServiceBusResource
Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.
addAzureServiceBus("messaging");await const serviceBus: AzureServiceBusResource
serviceBus.AzureBicepResource.publishAsExisting(name: string | ParameterResource, resourceGroup?: string | ParameterResource): AzureServiceBusResource (+1 overload)
Marks the resource as an existing resource when the application is deployed.
publishAsExisting(const existingBusName: ParameterResource
existingBusName, const existingBusResourceGroup: ParameterResource
existingBusResourceGroup);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();Use RunAsExisting when only local run mode should use the existing resource, PublishAsExisting when only deployed Azure environments should use it, and AsExisting when both modes should point at the same Azure resource.
Manage default role assignments
Section titled “Manage default role assignments”Aspire automatically assigns Azure RBAC roles based on how resources reference one another. When you need to opt out of those defaults before applying different permissions, use ClearDefaultRoleAssignments.
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureServiceBus("messaging") .ClearDefaultRoleAssignments();
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const serviceBus: AzureServiceBusResource
serviceBus = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureServiceBus(name: string): AzureServiceBusResource
Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.
addAzureServiceBus("messaging");await const serviceBus: AzureServiceBusResource
serviceBus.AzureBicepResource.clearDefaultRoleAssignments(): IAzureResource
Clears all default role assignments for the specified Azure resource.
clearDefaultRoleAssignments();
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();For built-in and custom RBAC guidance, see Manage Azure role assignments.
Read generated output values
Section titled “Read generated output values”Azure resources expose output references for values that Azure assigns during provisioning. Use those references when another resource, deployment step, or app setting needs the resolved Azure value.
var builder = DistributedApplication.CreateBuilder(args);
var identity = builder.AddAzureUserAssignedIdentity("identity");
builder.AddProject<Projects.Api>("api") .WithEnvironment("IDENTITY_CLIENT_ID", identity.Resource.ClientId);
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const identity: AzureUserAssignedIdentityResource
identity = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureUserAssignedIdentity(name: string): AzureUserAssignedIdentityResource
Adds an Azure user‑assigned identity resource to the application model.
addAzureUserAssignedIdentity("identity");const const clientId: BicepOutputReference
clientId = await const identity: AzureUserAssignedIdentityResource
identity.AzureUserAssignedIdentityResource.getOutput(name: string): BicepOutputReference
Gets a reference to an output from a bicep template.
getOutput("clientId");
const const api: ProjectResource
api = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: { launchProfileOrOptions?: ProjectResourceOptions;}): ProjectResource (+1 overload)
Adds a .NET project resource
addProject("api", "../Api/Api.csproj");await const api: ProjectResource
api.ProjectResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): ProjectResource
Sets an environment variable
withEnvironment("IDENTITY_CLIENT_ID", const clientId: BicepOutputReference
clientId);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();Use GetBicepIdentifier() inside ConfigureInfrastructure or infrastructure resolvers when you need a stable identifier for a provisioned Azure construct. Use output references such as ClientId, NameOutputReference, or getOutput("...") when you need Azure-assigned values like a client ID, endpoint, or resource name.
Azure.Provisioning customization
Section titled “Azure.Provisioning customization”The ConfigureInfrastructure API lets you customize the Azure resources that Aspire generates during provisioning. In C#, it provides a strongly-typed surface over the Azure.Provisioning library, letting you modify any property of the generated Azure resource types before Bicep is emitted.
Basic infrastructure customization
Section titled “Basic infrastructure customization”All Azure hosting resources in Aspire inherit from AzureProvisioningResource, which exposes ConfigureInfrastructure. The callback receives an AzureResourceInfrastructure instance that gives you access to all provisioned constructs for that resource.
In C#, use GetProvisionableResources() with the strongly-typed Azure SDK types (for example StorageAccount, ServiceBusNamespace) to navigate and mutate each construct:
var builder = DistributedApplication.CreateBuilder(args);
var storage = builder.AddAzureStorage("storage");
storage.ConfigureInfrastructure(infra =>{ var storageAccount = infra.GetProvisionableResources() .OfType<StorageAccount>() .Single();
storageAccount.Sku = new StorageSku { Name = StorageSkuName.PremiumLRS };
storageAccount.Tags["Environment"] = "Development"; storageAccount.Tags["CostCenter"] = "Engineering";});
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const storage: AzureStorageResource
storage = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureStorage(name: string): AzureStorageResource
Adds an Azure Storage resource to the application model. This resource can be used to create Azure blob, table, and queue resources.
addAzureStorage("storage");
await const storage: AzureStorageResource
storage.AzureProvisioningResource.configureInfrastructure(configure: (obj: AzureResourceInfrastructure) => Promise<void>): AzureProvisioningResource
Configures the Azure provisioning infrastructure callback
configureInfrastructure(async (infra: AzureResourceInfrastructure
infra) => { // Strongly-typed Azure SDK types are not available in TypeScript. // Use getProvisionableResources() to access constructs dynamically. const const resources: any[]
resources = await infra: AzureResourceInfrastructure
infra.AzureResourceInfrastructure.getProvisionableResources(): Promise<any[]>
Gets the provisionable Azure resources produced by the infrastructure callback.
getProvisionableResources(); // Work with resources generically as needed.});
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();Configure SKUs and tiers
Section titled “Configure SKUs and tiers”storage.ConfigureInfrastructure(infra =>{ var account = infra.GetProvisionableResources() .OfType<StorageAccount>() .Single();
account.Sku = new StorageSku { Name = StorageSkuName.StandardGRS }; account.Kind = StorageKind.StorageV2;});serviceBus.ConfigureInfrastructure(infra =>{ var ns = infra.GetProvisionableResources() .OfType<ServiceBusNamespace>() .Single();
ns.Sku = new ServiceBusSku { Name = ServiceBusSkuName.Premium, Capacity = 2 };});redis.ConfigureInfrastructure(infra =>{ var cache = infra.GetProvisionableResources() .OfType<RedisCache>() .Single();
cache.Sku = new RedisCacheSku { Name = RedisCacheSkuName.Premium, Family = RedisCacheSkuFamily.P, Capacity = 1 };});Configure networking
Section titled “Configure networking”storage.ConfigureInfrastructure(infra =>{ var account = infra.GetProvisionableResources() .OfType<StorageAccount>() .Single();
account.NetworkRuleSet = new StorageAccountNetworkRuleSet { DefaultAction = StorageNetworkDefaultAction.Deny, Bypass = "AzureServices" };
account.NetworkRuleSet.IpRules.Add(new StorageAccountIPRule { IPAddressOrRange = "203.0.113.0/24", Action = "Allow" });});Configure security and compliance
Section titled “Configure security and compliance”storage.ConfigureInfrastructure(infra =>{ var account = infra.GetProvisionableResources() .OfType<StorageAccount>() .Single();
account.EnableHttpsTrafficOnly = true; account.MinimumTlsVersion = StorageMinimumTlsVersion.Tls1_2;
account.Encryption = new StorageAccountEncryption { KeySource = StorageAccountKeySource.MicrosoftStorage, Services = new StorageAccountEncryptionServices { Blob = new StorageEncryptionService { Enabled = true }, File = new StorageEncryptionService { Enabled = true } } };});Work with multiple resources
Section titled “Work with multiple resources”When an integration creates multiple resources (for example, a Service Bus namespace and its queues), you can customize each one inside a single ConfigureInfrastructure call:
var servicebus = builder.AddAzureServiceBus("messaging");var queue = servicebus.AddQueue("orders");
servicebus.ConfigureInfrastructure(infra =>{ var ns = infra.GetProvisionableResources() .OfType<ServiceBusNamespace>() .Single(); ns.Sku = new ServiceBusSku { Name = ServiceBusSkuName.Standard };
var queueResource = infra.GetProvisionableResources() .OfType<ServiceBusQueue>() .FirstOrDefault(q => q.Name.Contains("orders"));
if (queueResource != null) { queueResource.MaxDeliveryCount = 5; queueResource.DefaultMessageTimeToLive = TimeSpan.FromHours(24); }});Add Azure resources to the infrastructure
Section titled “Add Azure resources to the infrastructure”For common scenarios, prefer Aspire’s higher-level resource builders. For example, to add a private endpoint to a storage account, use AddPrivateEndpoint from the Aspire.Hosting.Azure.Network package, which automatically wires up the Private DNS Zone, VNet link, and DNS Zone Group:
var builder = DistributedApplication.CreateBuilder(args);
var vnet = builder.AddAzureVirtualNetwork("vnet");var peSubnet = vnet.AddSubnet("pe-subnet", "10.0.1.0/24");
var storage = builder.AddAzureStorage("storage");var blobs = storage.AddBlobs("blobs");
peSubnet.AddPrivateEndpoint(blobs);
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const vnet: AzureVirtualNetworkResource
vnet = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureVirtualNetwork(name: string, options?: { addressPrefix?: string | ParameterResource;}): AzureVirtualNetworkResource (+1 overload)
Adds an Azure Virtual Network resource to the application model.
addAzureVirtualNetwork("vnet");const const peSubnet: AzureSubnetResource
peSubnet = const vnet: AzureVirtualNetworkResource
vnet.AzureVirtualNetworkResource.addSubnet(name: string, addressPrefix: string | ParameterResource, options?: { subnetName?: string;} | undefined): AzureSubnetResource (+1 overload)
Adds an Azure subnet resource to an Azure Virtual Network resource.
addSubnet("pe-subnet", "10.0.1.0/24");
const const storage: AzureStorageResource
storage = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addAzureStorage(name: string): AzureStorageResource
Adds an Azure Storage resource to the application model. This resource can be used to create Azure blob, table, and queue resources.
addAzureStorage("storage");const const blobs: AzureBlobStorageResource
blobs = const storage: AzureStorageResource
storage.AzureStorageResource.addBlobs(name: string): AzureBlobStorageResource
Adds an Azure Blob Storage resource
addBlobs("blobs");
const peSubnet: AzureSubnetResource
peSubnet.AzureSubnetResource.addPrivateEndpoint(target: IAzurePrivateEndpointTarget): AzurePrivateEndpointResource
Adds an Azure Private Endpoint resource to the subnet.
addPrivateEndpoint(const blobs: AzureBlobStorageResource
blobs);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();When no Aspire-native resource builder exists for what you need, fall back to ConfigureInfrastructure to add an Azure.Provisioning construct directly. See the Azure.Provisioning API reference for the available construct types and their properties.
Customize naming and provisioning with an infrastructure resolver
Section titled “Customize naming and provisioning with an infrastructure resolver”Another way to customize Azure provisioning is to create an InfrastructureResolver. This is a C#-only API that lets you apply organization-wide naming conventions or other centralized provisioning behavior across many Azure resources.
Define a resolver by inheriting from InfrastructureResolver and overriding the relevant virtual members:
using Azure.Provisioning;using Azure.Provisioning.CosmosDB;using Azure.Provisioning.Primitives;
internal sealed class FixedNameInfrastructureResolver : InfrastructureResolver{ public override void ResolveProperties(ProvisionableConstruct construct, ProvisioningBuildOptions options) { if (construct is CosmosDBAccount account) { account.Name = "ContosoCosmosDb"; }
base.ResolveProperties(construct, options); }}Register the resolver in the AppHost:
using Aspire.Hosting.Azure;using Microsoft.Extensions.DependencyInjection;
var builder = DistributedApplication.CreateBuilder(args);
builder.Services.Configure<AzureProvisioningOptions>(options =>{ options.ProvisioningBuildOptions.InfrastructureResolvers.Add(new FixedNameInfrastructureResolver());});
builder.Build().Run();Custom Bicep templates
Section titled “Custom Bicep templates”For scenarios requiring full control, you can supply a custom Bicep file and reference it from your AppHost. This approach works in both C# and TypeScript.
Use custom Bicep files
Section titled “Use custom Bicep files”Create a Bicep file in your AppHost project:
@description('Storage account name')param storageAccountName string
@description('Location')param location string = resourceGroup().location
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = { name: storageAccountName location: location sku: { name: 'Premium_LRS' } kind: 'BlockBlobStorage' properties: { minimumTlsVersion: 'TLS1_2' allowBlobPublicAccess: false networkAcls: { defaultAction: 'Deny' bypass: 'AzureServices' } }}
output storageAccountName string = storageAccount.nameReference the file from the AppHost using AddBicepTemplate (C#) or addBicepTemplate (TypeScript). Use WithParameter / withParameter to supply input parameters, and GetOutput / getOutput to consume a named output by passing the resulting reference to another resource:
var builder = DistributedApplication.CreateBuilder(args);
var storage = builder.AddBicepTemplate("storage", "./custom-storage.bicep") .WithParameter("storageAccountName", "mystorageaccount");
builder.AddProject<Projects.WebApp>("webapp") .WithEnvironment("STORAGE_ACCOUNT_NAME", storage.GetOutput("storageAccountName"));
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const storage: AzureBicepResource
storage = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addBicepTemplate(name: string, bicepFile: string): AzureBicepResource
Adds an Azure Bicep resource to the application model.
addBicepTemplate("storage", "./custom-storage.bicep");await const storage: AzureBicepResource
storage.AzureBicepResource.withParameter(name: string, options?: { value?: string | string[] | ParameterResource | IResourceWithConnectionString | BicepOutputReference | ReferenceExpression | EndpointReference;} | undefined): AzureBicepResource (+1 overload)
Adds a Bicep parameter
withParameter("storageAccountName", { value?: string | string[] | ParameterResource | IResourceWithConnectionString | BicepOutputReference | ReferenceExpression | EndpointReference | undefined
value: "mystorageaccount" });
const const storageAccountName: BicepOutputReference
storageAccountName = await const storage: AzureBicepResource
storage.AzureBicepResource.getOutput(name: string): BicepOutputReference
Gets a reference to an output from a bicep template.
getOutput("storageAccountName");
const const webapp: ProjectResource
webapp = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: { launchProfileOrOptions?: ProjectResourceOptions;}): ProjectResource (+1 overload)
Adds a .NET project resource
addProject("webapp", "../WebApp/WebApp.csproj");await const webapp: ProjectResource
webapp.ProjectResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): ProjectResource
Sets an environment variable
withEnvironment("STORAGE_ACCOUNT_NAME", const storageAccountName: BicepOutputReference
storageAccountName);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();Pass parameters and read outputs
Section titled “Pass parameters and read outputs”WithParameter accepts several kinds of values beyond plain strings, so a custom Bicep template can take values that are computed at deployment time. Common sources include:
- A
ParameterResourcedeclared withAddParameter(including secret parameters). - A
BicepOutputReferencefrom another Bicep resource — useful when one template’s output feeds another template’s input. - A
ReferenceExpressionthat composes values from multiple resources. - A connection-string-bearing resource via
IResourceBuilder<IResourceWithConnectionString>. - An
EndpointReferencefrom a resource’s endpoint.
The example below adds a secret administrator password as a parameter and then reads the deployed SQL server name back out of the template so that another resource can consume it:
Create the following Bicep file in your AppHost directory:
@secure()param administratorLoginPassword string
param location string = resourceGroup().location
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = { name: 'sql-${uniqueString(resourceGroup().id)}' location: location properties: { administratorLogin: 'sqladmin' administratorLoginPassword: administratorLoginPassword }}
output sqlServerName string = sqlServer.namevar builder = DistributedApplication.CreateBuilder(args);
var adminPassword = builder.AddParameter("adminPassword", secret: true);
var sql = builder.AddBicepTemplate("sql", "./custom-sql.bicep") .WithParameter("administratorLoginPassword", adminPassword);
builder.AddProject<Projects.Api>("api") .WithEnvironment("SQL_SERVER_NAME", sql.GetOutput("sqlServerName"));
builder.Build().Run();import { function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder } from './.aspire/modules/aspire.mjs';
const const builder: IDistributedApplicationBuilder
builder = await function createBuilder(): IDistributedApplicationBuilder
Creates a new distributed application builder
createBuilder();
const const adminPassword: ParameterResource
adminPassword = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addParameter(name: string, options?: { value?: string; publishValueAsDefault?: boolean; secret?: boolean;}): ParameterResource (+1 overload)
Adds a parameter resource
addParameter("adminPassword", { secret?: boolean | undefined
secret: true });
const const sql: AzureBicepResource
sql = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addBicepTemplate(name: string, bicepFile: string): AzureBicepResource
Adds an Azure Bicep resource to the application model.
addBicepTemplate("sql", "./custom-sql.bicep");await const sql: AzureBicepResource
sql.AzureBicepResource.withParameter(name: string, options?: { value?: string | string[] | ParameterResource | IResourceWithConnectionString | BicepOutputReference | ReferenceExpression | EndpointReference;} | undefined): AzureBicepResource (+1 overload)
Adds a Bicep parameter
withParameter("administratorLoginPassword", { value?: string | ParameterResource | string[] | IResourceWithConnectionString | BicepOutputReference | ReferenceExpression | EndpointReference | undefined
value: const adminPassword: ParameterResource
adminPassword });
const const sqlServerName: BicepOutputReference
sqlServerName = await const sql: AzureBicepResource
sql.AzureBicepResource.getOutput(name: string): BicepOutputReference
Gets a reference to an output from a bicep template.
getOutput("sqlServerName");
const const api: ProjectResource
api = await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: { launchProfileOrOptions?: ProjectResourceOptions;}): ProjectResource (+1 overload)
Adds a .NET project resource
addProject("api", "../Api/Api.csproj");await const api: ProjectResource
api.ProjectResource.withEnvironment(name: string, value: string | IResourceWithConnectionString | IValueProvider): ProjectResource
Sets an environment variable
withEnvironment("SQL_SERVER_NAME", const sqlServerName: BicepOutputReference
sqlServerName);
await const builder: IDistributedApplicationBuilder
builder.IDistributedApplicationBuilder.build(): DistributedApplication
Builds the distributed application
build().DistributedApplication.run(cancellationToken?: cancellationToken): void
Runs the distributed application
run();For more end-to-end examples — including chaining outputs between Bicep resources and using the existing Bicep keyword to reference resources that Aspire didn’t provision — see the Aspire playground/bicep sample.
Set the deployment scope
Section titled “Set the deployment scope”By default, Aspire deploys Bicep resources at the resource group scope. Some Bicep templates require a different deployment scope, such as the subscription or the tenant.
Set the Scope property on the Bicep resource using AzureBicepResourceScope.CreateForSubscription or AzureBicepResourceScope.CreateForTenant:
using Aspire.Hosting.Azure;
var builder = DistributedApplication.CreateBuilder(args);
var subscriptionId = builder.AddParameter("subscriptionId");
var subscriptionScoped = builder.AddBicepTemplateString( "subscriptionScoped", """ targetScope = 'subscription'
param location string
output value string = 'subscription' """);subscriptionScoped.Resource.Scope = AzureBicepResourceScope.CreateForSubscription(subscriptionId.Resource);
var tenantScoped = builder.AddBicepTemplateString( "tenantScoped", """ targetScope = 'tenant'
param location string
output value string = 'tenant' """);tenantScoped.Resource.Scope = AzureBicepResourceScope.CreateForTenant();
builder.Build().Run();Inspect generated Bicep
Section titled “Inspect generated Bicep”To see the Bicep that Aspire emits after applying your ConfigureInfrastructure callbacks, publish the AppHost and read the files from the output folder:
- From the AppHost directory, run
aspire publish. - Open the
aspire-outputfolder in the AppHost directory. To write somewhere else, pass--output-pathto the publish command. - Review the generated
.bicepfiles to verify your customizations.