Skip to content

Use Aspire 9's WaitFor feature for making projects wait for CloudFormation #14

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

Merged
merged 2 commits into from
Jan 24, 2025
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
11 changes: 11 additions & 0 deletions .autover/changes/e537d29a-c69e-46f0-a857-68c6a75b23d6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Aspire.Hosting.AWS",
"Type": "Patch",
"ChangelogMessages": [
"Use Aspire 9's WaitFor mechanism for waiting CloudFormation resource to be running"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ public static IResourceBuilder<TDestination> WithReference<TDestination>(this IR
/// <param name="configSection">The config section in IConfiguration to add the output parameters.</param>
/// <returns></returns>
public static IResourceBuilder<TDestination> WithReference<TDestination>(this IResourceBuilder<TDestination> builder, IResourceBuilder<ICloudFormationResource> cloudFormationResourceBuilder, string configSection = Constants.DefaultConfigSection)
where TDestination : IResourceWithEnvironment
where TDestination : IResourceWithEnvironment, IResourceWithWaitSupport
{
if (!cloudFormationResourceBuilder.Resource.Annotations.Any(x => x is CloudFormationReferenceAnnotation cf && string.Equals(cf.TargetResource, builder.Resource.Name, StringComparison.Ordinal)))
{
cloudFormationResourceBuilder.WithAnnotation(new CloudFormationReferenceAnnotation(builder.Resource.Name));
}

builder.WithEnvironment(async ctx =>
builder.WaitFor(cloudFormationResourceBuilder);

builder.WithEnvironment(ctx =>
{
if (ctx.ExecutionContext.IsPublishMode)
{
Expand All @@ -168,12 +170,6 @@ public static IResourceBuilder<TDestination> WithReference<TDestination>(this IR
SdkUtilities.ApplySDKConfig(ctx, cloudFormationResourceBuilder.Resource.AWSSDKConfig, false);
}

if (cloudFormationResourceBuilder.Resource.ProvisioningTaskCompletionSource is not null)
{
ctx.Logger?.LogInformation("Waiting on CloudFormation resource {Name} ...", cloudFormationResourceBuilder.Resource.Name);
await cloudFormationResourceBuilder.Resource.ProvisioningTaskCompletionSource.Task.WaitAsync(ctx.CancellationToken).ConfigureAwait(false);
}

if (cloudFormationResourceBuilder.Resource.Outputs == null)
{
return;
Expand Down
Loading