Skip to content
Merged
Changes from 2 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.

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.

Could we call out the lifecycle and permission change here? These scopes can create resources outside the AppHost resource group and require broader RBAC. The normal destroy path deletes the tracked resource group, so subscription- or tenant-level resources may remain.

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.

Please make an inline change suggestion—it's far easier.


<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"
Comment thread
IEvangelist marked this conversation as resolved.
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);

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.

This block is not compilable as shown. AzureBicepResourceScope is declared in Aspire.Hosting.Azure, while the AppHost SDK injects global usings only for Aspire.Hosting and Aspire.Hosting.ApplicationModel (source). A clean 13.5 staging AppHost fails here with CS0103. Please add using Aspire.Hosting.Azure; at the start of the block, or fully qualify the type.

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.

Fixed in 2a00c63 — added using Aspire.Hosting.Azure; at the top of the C# block so it compiles against a clean 13.5 AppHost, and the note now calls out the required directive explicitly.


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>
Comment on lines +686 to +690

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.

Good catch — addressed in 2a00c63. The note now explains that param location string is a well-known Aspire parameter the provisioner fills in automatically from the environment's location and passes to every Bicep deployment (subscription- and tenant-scoped ones included), so it should stay declared in the template.


</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
Loading