|
| 1 | +--- |
| 2 | +title: "Breaking change - Role Assignments separated from Azure resource bicep" |
| 3 | +description: "Learn about the breaking change in .NET Aspire 9.2 where role assignments are moved to separate bicep modules." |
| 4 | +ms.date: 4/2/2025 |
| 5 | +ai-usage: ai-assisted |
| 6 | +ms.custom: https://github.com/dotnet/docs-aspire/issues/2911 |
| 7 | +--- |
| 8 | + |
| 9 | +# Role Assignments separated from Azure resource bicep |
| 10 | + |
| 11 | +In .NET Aspire 9.2, role assignments for Azure resources are no longer included in the same bicep file as the resource. Instead, they're moved to separate bicep modules. This change affects how role assignments are customized during infrastructure configuration. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET Aspire 9.2 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, when an Azure resource's bicep file was generated, default role assignments were included in the same bicep module as the resource. This allowed customization of role assignments in the `ConfigureInfrastructure` callback. For example: |
| 20 | + |
| 21 | +```csharp |
| 22 | +var storage = builder.AddAzureStorage("storage") |
| 23 | + .ConfigureInfrastructure(infra => |
| 24 | + { |
| 25 | + var roles = infra.GetProvisionableResources().OfType<RoleAssignment>().ToList(); |
| 26 | + |
| 27 | + foreach (var role in roles) |
| 28 | + { |
| 29 | + infra.Remove(role); |
| 30 | + } |
| 31 | + |
| 32 | + var storageAccount = infra.GetProvisionableResources().OfType<StorageAccount>().Single(); |
| 33 | + infra.Add(storageAccount.CreateRoleAssignment(StorageBuiltInRole.StorageBlobDataContributor, ...)); |
| 34 | + }); |
| 35 | +``` |
| 36 | + |
| 37 | +## New behavior |
| 38 | + |
| 39 | +Role assignments are now moved to their own bicep modules. The `ConfigureInfrastructure` callback no longer contains any `RoleAssignment` instances. Instead, role assignments are configured using the `WithRoleAssignments` API. For example: |
| 40 | + |
| 41 | +```csharp |
| 42 | +var storage = builder.AddAzureStorage("storage"); |
| 43 | + |
| 44 | +builder.AddProject<Projects.AzureContainerApps_ApiService>("api") |
| 45 | + .WithRoleAssignments(storage, StorageBuiltInRole.StorageBlobDataContributor); |
| 46 | +``` |
| 47 | + |
| 48 | +## Type of breaking change |
| 49 | + |
| 50 | +This is a [behavioral change](../categories.md#behavioral-change). |
| 51 | + |
| 52 | +## Reason for change |
| 53 | + |
| 54 | +This change was necessary to implement the `WithRoleAssignments` APIs, which provide a more structured and flexible way to configure role assignments per application. |
| 55 | + |
| 56 | +## Recommended action |
| 57 | + |
| 58 | +To customize role assignments in .NET Aspire 9.2, use the `WithRoleAssignments` API instead of relying on the `ConfigureInfrastructure` callback. Update your code as shown in the [preceding example](#new-behavior). |
| 59 | + |
| 60 | +## Affected APIs |
| 61 | + |
| 62 | +- <xref:Aspire.Hosting.AzureProvisioningResourceExtensions.ConfigureInfrastructure``1(Aspire.Hosting.ApplicationModel.IResourceBuilder{``0},System.Action{Aspire.Hosting.Azure.AzureResourceInfrastructure})> |
0 commit comments