Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssignParameter(...) for CDK resources #2558

Merged
merged 4 commits into from
Mar 1, 2024
Merged

Conversation

mitchdenny
Copy link
Member

@mitchdenny mitchdenny commented Mar 1, 2024

This PR removes the specialized AddParameter(..) API we had for CDK and opts for a simpler pattern where we just have an AssignParameter extension which is available on Resource<T> objects (CDK resources that is). It follows the same pattern as the CDK variant and delegates to it, but it also correctly wires up the Aspire parameters so that AZD and the provisioner can work.

Sample code:

using Azure.Provisioning.Storage;
using Azure.ResourceManager.Storage.Models;

var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureProvisioning();

var sku = builder.AddParameter("storagesku");

var construct1 = builder.AddAzureConstruct("construct1", (construct) =>
{
    var account = construct.AddStorageAccount(
        name: "bob",
        kind: StorageKind.BlobStorage,
        sku: StorageSkuName.StandardLrs
        );
    account.AssignParameter(a => a.Sku.Name, sku);

    account.AddOutput(data => data.PrimaryEndpoints.TableUri, "tableUri", isSecure: true);
});

builder.AddProject<Projects.CdkSample_ApiService>("api")
       .WithEnvironment("TABLE_URI", construct1.GetOutput("tableUri"));

builder.Build().Run();

There is also a variant of the method that takes an string parameter support overriding the parameter name that is inserted. Its the functional equivalent of WithParameter(string, parameter).

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 1, 2024
@mitchdenny mitchdenny self-assigned this Mar 1, 2024
@mitchdenny mitchdenny added area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication and removed area-integrations Issues pertaining to Aspire Integrations packages labels Mar 1, 2024
@mitchdenny mitchdenny added this to the preview 4 (Mar) milestone Mar 1, 2024
@mitchdenny mitchdenny enabled auto-merge (squash) March 1, 2024 05:51
@mitchdenny mitchdenny merged commit 1cfe90b into main Mar 1, 2024
8 checks passed
@mitchdenny mitchdenny deleted the mitchdenny/assign-parameter branch March 1, 2024 06:22
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants