Skip to content

Need to sanitize bicep names from Aspire resource names #6074

Closed

Description

@eerhardt

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 David Fowler (@davidfowl) Mitch Denny (@mitchdenny) tg-msft

Activity

  1. added this to the 9.0 milestone on Oct 2, 2024
  2. added
    area-integrationsIssues pertaining to Aspire Integrations packages
    azureIssues associated specifically with scenarios tied to using Azure
    on Oct 2, 2024
  3. added 2 commits that reference this issue on Oct 4, 2024
    1ec42c6
    1d3356a
  4. added a commit that references this issue on Oct 5, 2024
    5603e92
  5. locked and limited conversation to collaborators on Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-integrationsIssues pertaining to Aspire Integrations packagesazureIssues associated specifically with scenarios tied to using Azure

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions