Skip to content

Commit 3d8bc03

Browse files
committed
fixup! AzureStorage auto create queues
1 parent 5753610 commit 3d8bc03

12 files changed

+37
-107
lines changed

src/Aspire.Hosting.Azure.Storage/AzureBlobStorageResource.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ internal ReferenceExpression GetConnectionString(string? blobContainerName)
3939
}
4040

4141
ReferenceExpressionBuilder builder = new();
42-
builder.Append($"{Endpoint}=\"{ConnectionStringExpression}\";");
43-
44-
if (!string.IsNullOrEmpty(blobContainerName))
45-
{
46-
builder.Append($"{ContainerName}={blobContainerName};");
47-
}
48-
42+
builder.Append($"{Endpoint}=\"{ConnectionStringExpression}\";{ContainerName}={blobContainerName};");
4943
return builder.Build();
5044
}
5145

src/Aspire.Hosting.Azure.Storage/AzureQueueStorageQueueResource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Aspire.Hosting;
1111

1212
/// <summary>
13-
/// A resource that represents an Azure Blob Storage queue.
13+
/// A resource that represents an Azure Storage queue.
1414
/// </summary>
1515
/// <param name="name">The name of the resource.</param>
1616
/// <param name="queueName">The name of the queue.</param>
@@ -25,7 +25,7 @@ public class AzureQueueStorageQueueResource(string name, string queueName, Azure
2525
public string QueueName { get; } = ThrowIfNullOrEmpty(queueName);
2626

2727
/// <summary>
28-
/// Gets the connection string template for the manifest for the Azure Blob Storage container resource.
28+
/// Gets the connection string template for the manifest for the Azure Storage queue resource.
2929
/// </summary>
3030
public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(QueueName);
3131

src/Aspire.Hosting.Azure.Storage/AzureQueueStorageResource.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ internal ReferenceExpression GetConnectionString(string? queueName)
3939
}
4040

4141
ReferenceExpressionBuilder builder = new();
42-
builder.Append($"{Endpoint}=\"{ConnectionStringExpression}\";");
43-
44-
if (!string.IsNullOrEmpty(queueName))
45-
{
46-
builder.Append($"{QueueName}={queueName};");
47-
}
48-
42+
builder.Append($"{Endpoint}=\"{ConnectionStringExpression}\";{QueueName}={queueName};");
4943
return builder.Build();
5044
}
5145

src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,43 @@ public static IResourceBuilder<AzureStorageResource> AddAzureStorage(this IDistr
7272
Tags = { { "aspire-resource-name", infrastructure.AspireResource.Name } }
7373
});
7474

75-
var blobs = new BlobService("blobs")
76-
{
77-
Parent = storageAccount
78-
};
79-
infrastructure.Add(blobs);
80-
81-
var queues = new QueueService("queues")
82-
{
83-
Parent = storageAccount
84-
};
85-
infrastructure.Add(queues);
86-
87-
infrastructure.Add(new ProvisioningOutput("blobEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.BlobUri });
88-
infrastructure.Add(new ProvisioningOutput("queueEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.QueueUri });
89-
infrastructure.Add(new ProvisioningOutput("tableEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.TableUri });
90-
9175
var azureResource = (AzureStorageResource)infrastructure.AspireResource;
9276

93-
foreach (var blobContainer in azureResource.BlobContainers)
77+
if (azureResource.BlobContainers.Count > 0)
9478
{
95-
var cdkBlobContainer = blobContainer.ToProvisioningEntity();
96-
cdkBlobContainer.Parent = blobs;
97-
infrastructure.Add(cdkBlobContainer);
79+
var blobs = new BlobService("blobs")
80+
{
81+
Parent = storageAccount
82+
};
83+
infrastructure.Add(blobs);
84+
85+
foreach (var blobContainer in azureResource.BlobContainers)
86+
{
87+
var cdkBlobContainer = blobContainer.ToProvisioningEntity();
88+
cdkBlobContainer.Parent = blobs;
89+
infrastructure.Add(cdkBlobContainer);
90+
}
9891
}
9992

100-
foreach (var queue in azureResource.Queues)
93+
if (azureResource.Queues.Count > 0)
10194
{
102-
var cdkQueue = queue.ToProvisioningEntity();
103-
cdkQueue.Parent = queues;
104-
infrastructure.Add(cdkQueue);
95+
var queues = new QueueService("queues")
96+
{
97+
Parent = storageAccount
98+
};
99+
infrastructure.Add(queues);
100+
foreach (var queue in azureResource.Queues)
101+
{
102+
var cdkQueue = queue.ToProvisioningEntity();
103+
cdkQueue.Parent = queues;
104+
infrastructure.Add(cdkQueue);
105+
}
105106
}
106107

108+
infrastructure.Add(new ProvisioningOutput("blobEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.BlobUri });
109+
infrastructure.Add(new ProvisioningOutput("queueEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.QueueUri });
110+
infrastructure.Add(new ProvisioningOutput("tableEndpoint", typeof(string)) { Value = storageAccount.PrimaryEndpoints.TableUri });
111+
107112
// We need to output name to externalize role assignments.
108113
infrastructure.Add(new ProvisioningOutput("name", typeof(string)) { Value = storageAccount.Name });
109114
};

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureBicepResourceTests.AddAzureStorageViaPublishMode.verified.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2024-01-01' = {
2323
}
2424
}
2525

26-
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
27-
name: 'default'
28-
parent: storage
29-
}
30-
31-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
32-
parent: storage
33-
}
34-
3526
output blobEndpoint string = storage.properties.primaryEndpoints.blob
3627

3728
output queueEndpoint string = storage.properties.primaryEndpoints.queue

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureBicepResourceTests.AddAzureStorageViaPublishModeEnableAllowSharedKeyAccessOverridesDefaultFalse.verified.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2024-01-01' = {
2323
}
2424
}
2525

26-
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
27-
name: 'default'
28-
parent: storage
29-
}
30-
31-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
32-
parent: storage
33-
}
34-
3526
output blobEndpoint string = storage.properties.primaryEndpoints.blob
3627

3728
output queueEndpoint string = storage.properties.primaryEndpoints.queue

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureBicepResourceTests.AddAzureStorageViaRunMode.verified.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2024-01-01' = {
2323
}
2424
}
2525

26-
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
27-
name: 'default'
28-
parent: storage
29-
}
30-
31-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
32-
parent: storage
33-
}
34-
3526
output blobEndpoint string = storage.properties.primaryEndpoints.blob
3627

3728
output queueEndpoint string = storage.properties.primaryEndpoints.queue

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureBicepResourceTests.AddAzureStorageViaRunModeAllowSharedKeyAccessOverridesDefaultFalse.verified.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2024-01-01' = {
2323
}
2424
}
2525

26-
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
27-
name: 'default'
28-
parent: storage
29-
}
30-
31-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
32-
parent: storage
33-
}
34-
3526
output blobEndpoint string = storage.properties.primaryEndpoints.blob
3627

3728
output queueEndpoint string = storage.properties.primaryEndpoints.queue

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureEnvironmentResourceTests.AzurePublishingContext_CapturesParametersAndOutputsCorrectly_WithSnapshot#01.verified.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ resource storage 'Microsoft.Storage/storageAccounts@2024-01-01' = {
2525
}
2626
}
2727

28-
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
29-
name: 'default'
30-
parent: storage
31-
}
32-
33-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
34-
parent: storage
35-
}
36-
3728
output blobEndpoint string = storage.properties.primaryEndpoints.blob
3829

3930
output queueEndpoint string = storage.properties.primaryEndpoints.queue

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureStorageExtensionsTests.ResourceNamesBicepValid.verified.bicep

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2024-01-01' = {
2626
parent: storage
2727
}
2828

29-
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
30-
parent: storage
31-
}
32-
3329
resource myContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2024-01-01' = {
3430
name: 'my-blob-container'
3531
parent: blobs
3632
}
3733

34+
resource queues 'Microsoft.Storage/storageAccounts/queueServices@2024-01-01' = {
35+
parent: storage
36+
}
37+
3838
resource myqueue 'Microsoft.Storage/storageAccounts/queueServices/queues@2024-01-01' = {
3939
name: 'my-queue'
4040
parent: queues

0 commit comments

Comments
 (0)