Skip to content

Instantly share code, notes, and snippets.

@captainsafia
Created January 15, 2025 23:02
Show Gist options
  • Save captainsafia/b41388d64df4dc9d8e3612f01a7c4686 to your computer and use it in GitHub Desktop.
Save captainsafia/b41388d64df4dc9d8e3612f01a7c4686 to your computer and use it in GitHub Desktop.

Aspire Pre-provisioned Resource Support

var builder = DistributedApplication.CreateBuilder(args);

var storage = builder.AddAzureStorage("storage").RunAsEmulator();
var queue = storage.AddQueues("queue");
var blob = storage.AddBlobs("blob");
var eventHubs = builder.AddAzureEventHubs("eventhubs").UseExisting().AddEventHub("myhub");
var serviceBus = builder.AddAzureServiceBus("messaging").UseExisting().WithQueue("myqueue");

builder.AddAzureFunctionsProject<Projects.AzureFunctionsEndToEnd_Functions>("funcapp")
    .WithExternalHttpEndpoints()
    .WithReference(eventHubs).WaitFor(eventHubs)
    .WithReference(serviceBus).WaitFor(serviceBus)
    .WithReference(blob)
    .WithReference(queue);

builder.Build().Run();

Implementation Details

  • UsePreprovisioned method a-la UseEmulator
    • Defined on AzureResource type
    • Requirement: How do we want to support customizing the already provisionedx resource?
    • Do we need to think about something for non-Azure resources?
      • Yes, we care about this not just for AWS but for SQL resources as well that are running locally.
        • How is local resource different from plain old connection string?
public static IResourceBuilder<AzureResource> UsePreprovisioned(this IResourceBuilder<AzureResource> builder)
{
    var configuration = builder.ApplicationBuilder.Configuration.GetSection(builder.Resource.Name);
    builder.Resource.BindOutputs(configuration)
    builder.Resource.Annotations.Add(new PreprovisionedResource());
    return builder;
}
  • PreprovosionedResource marker annotation
  • Where can resources come from?
    • Single resource group, single subscription, single location
  • Strongly-typed output parameters for each resource type?
  • Stages of the feature:
    • See types of resources below
  • Is pre-provisioned local-only or can you access pre-provisioned for production?
    • Only for local-dev
    • For both local and remote
  • Emulated locally, pre-provisioned in deployment
  • Pre-provisioned locally, Aspire-managed in deployment

Types of resources

  1. Create: Aspire-managed (what we have now)
  2. Update: Existing with permissions (pre-existing, not exclusive to Aspire, have admin permissions on it)
  3. Read: Existing but you have no permissions to write to it (e.g. modify persmission)

Min-bar: pre-existing resources in local and production (with global managed identity typed)

Proposed API:

public static IResourceBuilder<T> UseExisting(this IResourceBuilder<t> b, string subscriptionId = null, string resourceGroupName = null, string resourceName = null)

Resources have:

  • State
  • Behaviors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment