Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Add existing resources#2642

Closed
IEvangelist wants to merge 13 commits intodotnet:dotnet-aspire-9.1from
IEvangelist:add-existing-resources
Closed

Add existing resources#2642
IEvangelist wants to merge 13 commits intodotnet:dotnet-aspire-9.1from
IEvangelist:add-existing-resources

Conversation

@IEvangelist
Copy link
Copy Markdown
Member

@IEvangelist IEvangelist commented Feb 19, 2025

@dotnetrepoman dotnetrepoman Bot added the fundamentals Content related to fundamentals. label Feb 19, 2025
@eerhardt eerhardt self-requested a review February 19, 2025 17:26
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md
@IEvangelist IEvangelist force-pushed the add-existing-resources branch from 40ae2c6 to c4b43c6 Compare February 20, 2025 14:56
Comment thread docs/azure/integrations-overview.md
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/fundamentals/app-host-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
> [!NOTE]
> Not all APIs are available on all Azure resources. For example, some Azure resources can be containerized or emulated, while others cannot.

When it comes to specifying whether an Azure resource in the app model is an existing resource, you can use the `AsExisting` API. The `AsExisting` method marks the resource as an existing resource in both run and publish modes. You can query whether a resource has been marked as an existing resource, by calling the `IsExisting` extension method on the <xref:Aspire.Hosting.ApplicationModel.IResource>. For more information, see [Mark Azure resources as existing](#mark-azure-resources-as-existing).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like AsExisting should be in the table above. Was there a reason why it isn't?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt like it didn't belong since it does both modes, I suppose there could be a column with the applicable mode, or something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Table would be fine. We'd also want somewhere to capture the info I shared in #2642 (comment). A table might get a little too stuffy if we added all that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the info in #2642 (comment) belongs in a paragraph form here.

Having AsExisting in the table calls attention to it and puts it on the same level as RunAsExisting and PublishAsExisting. I think it belongs in the same spot(s).

Comment thread docs/azure/integrations-overview.md Outdated
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>

The consuming API project uses the connection string information with no knowledge of how the app host configured it. In "publish" mode, the code adds a new Azure Storage resource—which would be reflected in the [deployment manifest](../deployment/manifest-format.md) accordingly. When in "run" mode, the connection string corresponds to a configuration value visible to the app host. It's assumed that any and all role assignments for the target resource have been configured. This means, you'd likely configure an environment variable or a user secret to store the connection string. The configuration is resolved from the `ConnectionStrings__storage` (or `ConnectionStrings:storage`) configuration key. These configuration values can be viewed when the app runs. For more information, see [Resource details](../fundamentals/dashboard/explore.md#resource-details).

## Mark Azure resources as existing
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@captainsafia - what is your thoughts on moving this above Add existing Azure resources with connection strings?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that with this format we have a segue from the connection strings approach to the bicep one. Although it does make it seem like connection strings are preferred to bicep. We can consider re-arranging it and maybe making the connection string stuff an H3 under existing resources instead of an H2?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider re-arranging it and maybe making the connection string stuff an H3 under existing resources instead of an H2?

I like this idea.

Although it does make it seem like connection strings are preferred to bicep.

Yes, that was my thinking. I think we should suggest using the new "Existing" feature first, because it works so much better and enables so many more scenarios.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we restructure/flow of the article to be the following (only looking at H2s and only highlighting changes to H3):

  • Naming conventions and APIs for expressing Azure resources
  • Add Azure resources
    • Mark Azure resources as existing
    • Add existing Azure resources with connection strings
  • Infrastructure as code
  • Publishing

Perhaps both the existing APIs bits and the connection string blurbs should be H3s, under the Add Azure resources heading? Thoughts? Admittedly, there are other H3s and H4s that were omitted from here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like moving the "as existing" and "connection string" stuff lower than the "typical devloper experience" stuff. We should have the normal cases first - when you add a new resource, not use an existing one. I also like having "as existing" above "connection string". So I think this proposal sounds good to me.

The NATS JetStream functionality provides a built-in persistence engine called JetStream which enables messages to be stored and replayed at a later time. You can optionally provide a `srcMountPath` parameter to specify the path to the JetStream data directory on the host machine (the provided mount path maps to the container's `-sd` argument).
The NATS JetStream functionality provides a built-in persistence engine called JetStream which enables messages to be stored and replayed at a later time.

### Add NETS server resource with authentication parameters
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Add NETS server resource with authentication parameters
### Add NATS server resource with authentication parameters

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commits mistakenly came over from a rebase, I'll incorporate the feedback elsewhere. Thank you.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var username = builder.AddParameter("username", secret: true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var username = builder.AddParameter("username", secret: true);
var username = builder.AddParameter("username");

Typically we don't mark usernames as secret...?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commits mistakenly came over from a rebase, I'll incorporate the feedback elsewhere. Thank you.

Comment thread docs/azure/integrations-overview.md Outdated
```csharp
var builder = DistributedApplication.CreateBuilder();

var existingResourceName = builder.AddParameter("existingResourceName");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var existingResourceName = builder.AddParameter("existingResourceName");
var existingResourceName = builder.AddParameter("existingServiceBusName");

?

- Adds an Azure Service Bus resource named `messaging` to the builder.
- Calls the `RunAsExisting` method on the `serviceBus` resource builder, passing the `existingResourceName` parameter—alternatively, you can use the `string` parameter overload.
- Adds a queue named `queue` to the `serviceBus` resource.

Copy link
Copy Markdown
Member

@eerhardt eerhardt Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add that the ServiceBus is assumed to be in the same Resource Group as your app is using.

Comment thread docs/azure/integrations-overview.md Outdated
Comment on lines +104 to +106
var serviceBus = builder.AddAzureServiceBus("messaging")
.PublishAsExisting(existingResourceName)
.WithQueue("queue");
Copy link
Copy Markdown
Member

@eerhardt eerhardt Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var serviceBus = builder.AddAzureServiceBus("messaging")
.PublishAsExisting(existingResourceName)
.WithQueue("queue");
var serviceBus = builder.AddAzureServiceBus("messaging")
.PublishAsExisting(existingResourceName);

WithQueue was removed in 9.1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to convert it, use:

var serviceBus = builder.AddAzureServiceBus("messaging")
    .PublishAsExisting(existingResourceName);

serviceBus.AddServiceBusQueue("queue");

AddServiceBusQueue returns the queue resource. (Just like AddDatabase returns the child database resource)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks for helping out with this.

IEvangelist and others added 2 commits February 21, 2025 07:31
Co-authored-by: Safia Abdalla <safia@safia.rocks>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Comment thread docs/azure/integrations-overview.md
Comment thread docs/azure/integrations-overview.md
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
Comment thread docs/azure/integrations-overview.md Outdated
@davidfowl
Copy link
Copy Markdown
Member

We need to explain exactly how RunAsExisting and PublishAsExisting works (this is key to helping people understand and troubleshoot when things go wrong).

PublishAsExisting without a resource group is kinda pointless by default since we are creating a new resource group the first time you deploy. We should mention this somewhere…

@eerhardt
Copy link
Copy Markdown
Member

PublishAsExisting without a resource group is kinda pointless by default since we are creating a new resource group the first time you deploy.

Does it make sense that resource group is an optional parameter then? It doesn't seem optional. cc @captainsafia

@eerhardt
Copy link
Copy Markdown
Member

eerhardt commented Feb 21, 2025

Does it make sense that resource group is an optional parameter then?

It should be possible to publish to an existing RG, right? https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/resource-group-scoped-deployments

But that case might be less common, so maybe it is better to require the dev to explicitly say null to mean "use current".

@captainsafia
Copy link
Copy Markdown
Contributor

But that case might be less common, so maybe it is better to require the dev to explicitly say null to mean "use current".

I don't think we necessarily need to change the existing signatures in 9.1 to react to this. If we do, I'd prefer that we change to making the resource group a required parameter on the PublishAsExisting and AsExisting methods.

That being said, I think the immediate problem that @davidfowl is more about how explicit we want to be about what happens under the hood in the docs. Right now, we show the generated aspire-manifest and bicep definitions when you publish but don't necessarily explain what those deltas mean in the bigger context of the deployment.

@IEvangelist
Copy link
Copy Markdown
Member Author

Closed by #2653

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fundamentals Content related to fundamentals.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants