Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/Aspire.Hosting.Azure/AzureResourcePreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ private async Task BuildRoleAssignmentAnnotations(DistributedApplicationModel ap
.ToLookup(a => a.Target);
foreach (var azureReference in azureReferences.OfType<AzureProvisioningResource>())
{
if (azureReference.IsContainer())
{
// Skip emulators
continue;
}

var roleAssignments = azureReferencesWithRoleAssignments[azureReference];
if (roleAssignments.Any())
{
Expand Down
26 changes: 24 additions & 2 deletions tests/Aspire.Hosting.Azure.Tests/AzureResourcePreparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task AppliesDefaultRoleAssignmentsInRunModeIfReferenced(bool addCon

var storageRolesManifest = await GetManifestWithBicep(storageRoles, skipPreparer: true);
await Verify(storageRolesManifest.BicepText, extension: "bicep");

}
else
{
Expand Down Expand Up @@ -115,7 +115,7 @@ public async Task AppliesRoleAssignmentsInRunMode(DistributedApplicationOperatio

var storageRolesManifest = await GetManifestWithBicep(storageRoles, skipPreparer: true);
await Verify(storageRolesManifest.BicepText, extension: "bicep");

}
else
{
Expand All @@ -133,6 +133,28 @@ public async Task AppliesRoleAssignmentsInRunMode(DistributedApplicationOperatio
}
}

[Fact]
public async Task DoesNotApplyRoleAssignmentsInRunModeForEmulators()
{
using var builder = TestDistributedApplicationBuilder.Create(DistributedApplicationOperation.Run);
builder.AddAzureContainerAppEnvironment("env");

builder.AddBicepTemplateString("foo", "");

var dbsrv = builder.AddAzureSqlServer("dbsrv").RunAsContainer();
var db = dbsrv.AddDatabase("db");

var api = builder.AddProject<Project>("api", launchProfileName: null)
.WithReference(db);

using var app = builder.Build();
var model = app.Services.GetRequiredService<DistributedApplicationModel>();
await ExecuteBeforeStartHooksAsync(app, default);

// in RunMode, we skip applying the role assignments to a new 'dbsrv-roles' resource, since the storage is running as emulator.
Assert.DoesNotContain(model.Resources.OfType<AzureProvisioningResource>(), r => r.Name == "dbsrv-roles");
}

[Fact]
public async Task FindsAzureReferencesFromArguments()
{
Expand Down
Loading