Skip to content

Commit 5bc26c7

Browse files
eerhardtdavidfowl
andauthored
Skip role assignment handling for emulators (#9705) (#9716)
- Updated `BuildRoleAssignmentAnnotations` to skip processing for container emulators. - Added a new test `DoesNotApplyRoleAssignmentsInRunModeForEmulators` to verify that role assignments are not applied to emulator resources. Co-authored-by: David Fowler <[email protected]>
1 parent 26bef51 commit 5bc26c7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Aspire.Hosting.Azure/AzureResourcePreparer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ private async Task BuildRoleAssignmentAnnotations(DistributedApplicationModel ap
143143
.ToLookup(a => a.Target);
144144
foreach (var azureReference in azureReferences.OfType<AzureProvisioningResource>())
145145
{
146+
if (azureReference.IsContainer())
147+
{
148+
// Skip emulators
149+
continue;
150+
}
151+
146152
var roleAssignments = azureReferencesWithRoleAssignments[azureReference];
147153
if (roleAssignments.Any())
148154
{

tests/Aspire.Hosting.Azure.Tests/AzureResourcePreparerTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ await Verifier.Verify(storageRolesManifest.BicepText, extension: "bicep")
133133
}
134134
}
135135

136+
[Fact]
137+
public async Task DoesNotApplyRoleAssignmentsInRunModeForEmulators()
138+
{
139+
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);
140+
builder.AddAzureContainerAppEnvironment("env");
141+
142+
builder.AddBicepTemplateString("foo", "");
143+
144+
var dbsrv = builder.AddAzureSqlServer("dbsrv").RunAsContainer();
145+
var db = dbsrv.AddDatabase("db");
146+
147+
var api = builder.AddProject<Project>("api", launchProfileName: null)
148+
.WithReference(db);
149+
150+
using var app = builder.Build();
151+
var model = app.Services.GetRequiredService<DistributedApplicationModel>();
152+
await ExecuteBeforeStartHooksAsync(app, default);
153+
154+
// in RunMode, we skip applying the role assignments to a new 'dbsrv-roles' resource, since the storage is running as emulator.
155+
Assert.DoesNotContain(model.Resources.OfType<AzureProvisioningResource>(), r => r.Name == "dbsrv-roles");
156+
}
157+
136158
[Fact]
137159
public async Task FindsAzureReferencesFromArguments()
138160
{

0 commit comments

Comments
 (0)