Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,59 @@ await builder.build().run();
</TabItem>
</Tabs>

### Set the deployment scope

By default, Aspire deploys Bicep resources at the resource group scope. Some Bicep templates require a different [deployment scope](https://learn.microsoft.com/azure/azure-resource-manager/bicep/deploy-to-subscription), such as the subscription or the tenant.

<Tabs syncKey="aspire-lang">
<TabItem id="csharp" label="C#">

Set the `Scope` property on the Bicep resource using `AzureBicepResourceScope.CreateForSubscription` or `AzureBicepResourceScope.CreateForTenant`:

```csharp title="AppHost.cs"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also provide the typescript sample, or explain why it's not supported

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot, please address this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9ec0e8c. I updated the “Set the deployment scope” section to include C#/TypeScript tabs and added a TypeScript note explaining that AzureBicepResourceScope/Resource.Scope aren’t currently exposed in the TypeScript AppHost APIs.

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();
```

<Aside type="note">
`targetScope` in the Bicep template must match the scope you assign in C#. `CreateForSubscription` requires a subscription identifier; `CreateForTenant` targets the current tenant and takes no arguments.
</Aside>

</TabItem>
<TabItem id="typescript" label="TypeScript">

<Aside type="note">
`AzureBicepResourceScope` and `Resource.Scope` are not currently exposed in the TypeScript AppHost APIs, so subscription/tenant deployment scopes for Bicep resources are currently C# only.
</Aside>

</TabItem>
</Tabs>

### Inspect generated Bicep

After customizing with `ConfigureInfrastructure`, inspect the Bicep that Aspire generates:
Expand Down