Support referencing existing Service Bus resources in references#7249
Support referencing existing Service Bus resources in references#7249captainsafia merged 11 commits intomainfrom
Conversation
This should be a draft right? |
| } | ||
|
|
||
| [Fact] | ||
| public async Task RequiresPublishAsExistingInPublishMode() |
There was a problem hiding this comment.
(nit) Is this test name correct? the test calls RunAsExisting
There was a problem hiding this comment.
Yeah, the test name is correct although confusing. I was intending to say that you need to call PublishAsExisting in publish-mode otherwise the API effectively no-ops.
| @@ -86,7 +96,7 @@ public static IResourceBuilder<AzureServiceBusResource> AddAzureServiceBus(this | |||
| infrastructure.Add(cdkRule); | |||
There was a problem hiding this comment.
Does generating these Queues and Topics work with an existing resource?
eerhardt
left a comment
There was a problem hiding this comment.
Looks really good. Nice work @captainsafia.
| // This could be done as a bicep template that imports the other bicep template but this is | ||
| // quick and dirty for now | ||
| var keyVaults = context.ResourceGroup.GetKeyVaults(); | ||
| var keyVaults = resourceGroup.GetKeyVaults(); |
There was a problem hiding this comment.
Testing this code path is interesting...
| if (builder.Resource.IsExisting()) | ||
| { | ||
| throw new InvalidOperationException($"Resource {builder.Resource.Name} is already marked as an existing resource."); | ||
| } |
There was a problem hiding this comment.
Why throw instead of replace?
There was a problem hiding this comment.
I feel like it makes it clearer to reason through the scope a resource is grouped to if we only support one XAsExisting invocation on a resource.
There was a problem hiding this comment.
We need to think about this like a pipeline. It should not throw
…isting-resources-1
| /// </summary> | ||
| /// <remarks> | ||
| /// The scope is a weakly-typed collection of key-value pairs that can be used to configure | ||
| /// the Bicep scope that is emitted by AZD in the module definition for a resource. |
| /// versions azure.bicep.v1. Only the `resourceGroup` key is respected as a sub-property although | ||
| /// more keys may be supported in the future, such as a subscriptionId. | ||
| /// </remarks> | ||
| public Dictionary<string, object> Scope { get; } = []; |
Opening this PR to sanity check the approach before adding it to other resource types. Some things of note:
FromExistingmethods should support setting scopes Azure/azure-sdk-for-net#47980. There are workarounds for the but the juice might not be worth the squeeze.ConfigureInfrastructurecalls for each resource.