aspire
aspire copied to clipboard
Need to sanitize bicep names from Aspire resource names
Today, Aspire resource names support hyphen - characters.
We take those resource names and use them for bicep variable names. For example:
https://github.com/dotnet/aspire/blob/aa34436aa9d168c3858a5e2fec231f4a746103da/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L43-L49
This doesn't work well because when you use a - in the name, you don't get an error until you try to azd up.
var storage = builder.AddAzureStorage("my-storage").RunAsEmulator(container =>
{
container.WithDataBindMount();
});
var blobs = storage.AddBlobs("blobs");
builder.AddProject<Projects.AzureStorageEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
.WithReference(blobs);
When you azd up, it produces:
Packaging services (azd package)
Provisioning Azure resources (azd provision)
Provisioning Azure resources can take some time.
ERROR: error executing step command 'provision': initializing provisioning manager: failed to compile bicep template: failed running bicep build: exit code: 1, stdout: , stderr: C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(2,7) : Warning no-unused-params: Parameter "location" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(4,7) : Warning no-unused-params: Parameter "principalId" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(6,7) : Warning no-unused-params: Parameter "principalType" is declared but never used. [https://aka.ms/bicep/linter/no-unused-params]
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(8,10) : Error BCP028: Identifier "my" is declared multiple times. Remove or rename the duplicates.
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(8,12) : Error BCP068: Expected a resource type string. Specify a valid resource type of format "<types>@<apiVersion>".
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(8,12) : Error BCP029: The resource type is not valid. Specify a valid resource type of format "<types>@<apiVersion>".
C:\Users\eerhardt\AppData\Local\Temp\azd-infra2898406436\my-storage\my-storage.module.bicep(8,71) : Error BCP018: Expected the "=" character at this location.
We need to sanitize these names, probably by replacing - with _ (which is safe to do because bicep supports underscore, and Aspire doesn't support underscore).
cc @davidfowl @mitchdenny @tg-msft