Skip to content

9.5.1 Regression from 9.4.1 with Keycloak #11966

Closed

Description

@RudyCo

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I tried to upgrade the excellent Keycloak Blueprint created by Julio Casal (@julioct) from Aspire 9.4.1 to 9.5.1.

For Keycloak, I changed the version to
<PackageReference Include="Aspire.Hosting.Keycloak" Version="9.5.1-preview.1.25502.11" />

Any idea about what's wrong with 9.5.1?
Thanks in advance!

PS: Here is the output after azd up or azd provision

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\rudyco\AppData\Local\Temp\azd-infra3768110317\cae\cae.module.bicep(4,7) : Warning no-unused-params: Parameter "userPrincipalId" is declared but never used. [https://aka.ms/bicep/linter-diagnostics#no-unused-params]
C:\Users\rudyco\AppData\Local\Temp\azd-infra3768110317\postgres\postgres.module.bicep(92,8) : Error BCP353: The outputs "hostName", "hostname" differ only in casing. The ARM deployments engine is not case sensitive and will not be able to distinguish between them. [https://aka.ms/bicep/core-diagnostics#BCP353]
C:\Users\rudyco\AppData\Local\Temp\azd-infra3768110317\postgres\postgres.module.bicep(94,8) : Error BCP353: The outputs "hostName", "hostname" differ only in casing. The ARM deployments engine is not case sensitive and will not be able to distinguish between them. [https://aka.ms/bicep/core-diagnostics#BCP353]
C:\Users\rudyco\AppData\Local\Temp\azd-infra3768110317\templateapp-api-roles-postgres-kv\templateapp-api-roles-postgres-kv.module.bicep(2,7) : Warning no-unused-params: Parameter "location" is declared but never used. [https://aka.ms/bicep/linter-diagnostics#no-unused-params]
C:\Users\rudyco\AppData\Local\Temp\azd-infra3768110317\main.bicep(16,7) : Warning no-unused-params: Parameter "KeycloakPassword" is declared but never used. [https://aka.ms/bicep/linter-diagnostics#no-unused-params]
C:\Users\rudyco\AppData\Local\Temp\azd-infra3768110317\main.bicep(39,17) : Error BCP104: The referenced module has errors. [https://aka.ms/bicep/core-diagnostics#BCP104]

Expected Behavior

No issue to deploy to Azure.

Steps To Reproduce

Download the Blueprint (link above).
Upgrade all the Aspire packages to 9.5.1 (preview for Keycloak)

Exceptions (if any)

See output logs.

.NET Version info

9.x

Anything else?

Maybe related to these PRs

Activity

  1. added
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Oct 11, 2025
  2. RudyCo commented on Oct 11, 2025

    @RudyCo
    ContributorAuthor

    I'm a bot. Here are possible related and/or duplicate issues (I may be wrong):

    You're a good bot but these 2 links don't help much, as we used to say in French : "Rien à voir avec la choucroute !" 😆

  3. added
    area-integrationsIssues pertaining to Aspire Integrations packages
    and removed
    needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
    on Oct 12, 2025
  4. davidfowl commented on Oct 12, 2025

    @davidfowl
    Collaborator

    Can you share the code in the apphost?

  5. RudyCo commented on Oct 12, 2025

    @RudyCo
    ContributorAuthor

    Can you share the code in the apphost?

    Here it is...

    using Azure.Provisioning;
    using Azure.Provisioning.PostgreSql;
    
    var builder = DistributedApplication.CreateBuilder(args);
    
    var postgres = builder.AddAzurePostgresFlexibleServer("postgres")
                        .RunAsContainer(postgres =>
                        {
                            postgres.WithDataVolume();
                            postgres.WithPgAdmin(pgAdmin =>
                            {
                                pgAdmin.WithHostPort(5050);
                            });
                        })
                        .ConfigureInfrastructure(infra =>
                        {
                            var pg = infra.GetProvisionableResources().OfType<PostgreSqlFlexibleServer>().Single();
    
                            infra.Add(new ProvisioningOutput("hostname", typeof(string))
                            {
                                Value = pg.FullyQualifiedDomainName
                            });
                        });
    
    var templateAppDb = postgres.AddDatabase("TemplateAppDB", "TemplateApp");
    
    var keycloakPassword = builder.AddParameter("KeycloakPassword", secret: true, value: "admin");
    var keycloak = builder.AddKeycloak("keycloak", adminPassword: keycloakPassword)
                          .WithLifetime(ContainerLifetime.Persistent);
    
    if (builder.ExecutionContext.IsRunMode)
    {
        keycloak.WithDataVolume()
                .WithRealmImport("./realms");
    }
    
    if (builder.ExecutionContext.IsPublishMode)
    {
        var postgresUser = builder.AddParameter("PostgresUser", value: "postgres");
        var postgresPassword = builder.AddParameter("PostgresPassword", secret: true);
        postgres.WithPasswordAuthentication(userName: postgresUser, password: postgresPassword);
    
        var keycloakDb = postgres.AddDatabase("keycloakDB", "keycloak");
    
        var keycloakDbUrl = ReferenceExpression.Create(
            $"jdbc:postgresql://{postgres.GetOutput("hostName")}/{keycloakDb.Resource.DatabaseName}"
        );
    
        keycloak.WithEnvironment("KC_HTTP_ENABLED", "true")
                .WithEnvironment("KC_PROXY_HEADERS", "xforwarded")
                .WithEnvironment("KC_HOSTNAME_STRICT", "false")
                .WithEnvironment("KC_DB", "postgres")
                .WithEnvironment("KC_DB_URL", keycloakDbUrl)
                .WithEnvironment("KC_DB_USERNAME", postgresUser)
                .WithEnvironment("KC_DB_PASSWORD", postgresPassword)
                .WithEndpoint("http", e => e.IsExternal = true);
    }
    
    builder.AddAzureContainerAppEnvironment("cae");
    
    builder.Build().Run();
    
  6. RudyCo commented on Oct 12, 2025

    @RudyCo
    ContributorAuthor

    The azd infra generate commands creates the same output twice in the postgres.module.bicep file:

    output hostName string = postgres.properties.fullyQualifiedDomainName
    output hostname string = postgres.properties.fullyQualifiedDomainName
    

    Commenting this code, fixes the issue:

    .ConfigureInfrastructure(infra =>
    {
        var pg = infra.GetProvisionableResources().OfType<PostgreSqlFlexibleServer>().Single();
    
        infra.Add(new ProvisioningOutput("hostname", typeof(string))
        {
            Value = pg.FullyQualifiedDomainName
        });
    });
    
  7. RudyCo commented on Oct 12, 2025

    @RudyCo
    ContributorAuthor

    It's possibly more a breaking change rather than a regression.
    Maybe infra.Add(new ProvisioningOutput("hostname", typeof(string)) should raise an exception in case the output key is already provided by Aspire.

  8. davidfowl commented on Oct 12, 2025

    @davidfowl
    Collaborator

    Yes, we made improvements here that make it so you don't need to add the output.

    FYI Julio Casal (@julioct)

  9. julioct commented on Oct 14, 2025

    @julioct
    Contributor

    Thank you for reporting this, RudyCo (@RudyCo). I just confirmed this is enough to create the PosgreSQL resource now:

    var postgres = builder.AddAzurePostgresFlexibleServer("postgres")
                        .RunAsContainer(postgres =>
                        {
                            postgres.WithDataVolume();
                            postgres.WithPgAdmin(pgAdmin =>
                            {
                                pgAdmin.WithHostPort(5050);
                            });
                        });

    But you also need to update how you build the connection string for the Keycloak DB, using the new HostName property on the PostgreSQL resource:

    var keycloakDbUrl = ReferenceExpression.Create(
        $"jdbc:postgresql://{postgres.Resource.HostName}/{keycloakDb.Resource.DatabaseName}"
    );

    The template download at https://juliocasal.com/blueprint is now updated to 9.5 too.

  10. davidfowl commented on Oct 14, 2025

    @davidfowl
    Collaborator

    Julio Casal (@julioct) it will improve more in the next version #11938

  11. RudyCo commented on Oct 14, 2025

    @RudyCo
    ContributorAuthor

    Thanks Julio Casal (@julioct) for the confirmation.
    I am using SQL Server, so I updated the connection string as follows:
    [keycloakSql.Resource.FullyQualifiedDomainName](jdbc:sqlserver://{keycloakSql.Resource.FullyQualifiedDomainName})...

  12. julioct commented on Oct 14, 2025

    @julioct
    Contributor

    @julioct it will improve more in the next version #11938

    Beautiful!

  13. locked and limited conversation to collaborators on Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions