aspire: Azure Sql Provisioning Stopped Working

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I’m not sure where to file this, so I’m starting here since I hit it using aspire 9.3.

Long story short, today my builds starting failing in the provision step hooking up web to azure sql. Everything has been working for a couple weeks. I found an error on azure, linked from GitHub action, that pointed to https://www.powershellgallery.com/packages/SqlServer/22.4.5.1.

I did an azd infra generate and forced the package back to the previous version and everything is deploying again.

22.4.5.1 was released ~16 hours ago. I noticed a problem ~7 hours ago.

I can’t find the source code this script, so, I started here. Happy to resubmit in the right repo if I knew where it was.

Expected Behavior

Deploys successfully.

Steps To Reproduce

I would think anyone deploying to azure sql with aspire and identity would have a problem today.

Exceptions (if any)

No response

.NET Version info

.NET SDK: Version: 9.0.101 Commit: eedb237549 Workload version: 9.0.100-manifests.3068a692 MSBuild version: 17.12.12+1cce77968

Runtime Environment: OS Name: Mac OS X OS Version: 15.5 OS Platform: Darwin RID: osx-arm64 Base Path: /usr/local/share/dotnet/sdk/9.0.101/

.NET workloads installed: There are no installed workloads to display. Configured to use loose manifests when installing new manifests.

Host: Version: 9.0.0 Architecture: arm64 Commit: 9d5a6a9aa4

.NET SDKs installed: 8.0.300 [/usr/local/share/dotnet/sdk] 8.0.401 [/usr/local/share/dotnet/sdk] 9.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Here’s a workaround you can use until the patch is released:

using Aspire.Hosting.Azure;
using Azure.Provisioning;
using Azure.Provisioning.Primitives;
using Microsoft.Extensions.DependencyInjection;

var builder = DistributedApplication.CreateBuilder(args);

builder.Services.Configure<AzureProvisioningOptions>(options =>
{
    options.ProvisioningBuildOptions.InfrastructureResolvers.Add(new SqlScriptWorkaroundResolver());
});

var sql1 = builder.AddAzureSqlServer("sql1")

...


/// <summary>
/// Works around https://github.com/dotnet/aspire/issues/9926 by ensuring that the SqlServer module has the correct version
/// </summary>
internal sealed class SqlScriptWorkaroundResolver : InfrastructureResolver
{
    public override IEnumerable<Provisionable> ResolveResources(IEnumerable<Provisionable> resources, ProvisioningBuildOptions options)
    {
        foreach (var resource in resources)
        {
            if (resource is ProvisionableResource provisionable && provisionable.GetType().Name == "SqlServerScriptProvisioningResource")
            {
                var scriptContent = (BicepValue<string>)provisionable.ProvisionableProperties["ScriptContent"];
                var newscriptContent = scriptContent.Value!.Replace("Install-Module -Name SqlServer", "Install-Module -Name SqlServer -RequiredVersion 22.3.0");
                scriptContent.Assign(new BicepValue<string>(newscriptContent));
            }
        }
        return base.ResolveResources(resources, options);
    }
}

Appears to be working. Thanks for the quick patch.

FYI for folks impacted by this, the fix has now shipped. Please update your Aspire.Hosting.Azure.Sql Package reference to version 9.3.2 which should have the fix for this.

Not at a computer at the moment, but iirc, you can run azd infra generate from the root of your project. If you did azd init, there should be a next-steps markdown file present which has some information. The markdown calls it azd infra synth which still works but is deprecated.

That command will generate all of the bicep files. Then you’ll be able to find the powershell call and make the mod. Commit the files in your repo and what you changed will be used instead of the default.

After the patch is released, we should be able to delete these infra files and go back to using the defaults.

What is the estimate time to use this patch? I can not deploy anything of my project

I believe I’m experiencing the same issue - our pipeline began failing during the same timeframe described above.

Our Azure ‘sql-roles’ deployment is failing, with all individual deployment scripts unable to execute successfully. Upon examining the deployment script logs, I can see an error that it cannot locate the required System.Runtime version.

Import-Module: Could not load file or assembly 'System.Runtime, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the
file specified.

Import-Module: /mnt/azscripts/azscriptinput/userscript.ps1:8
Line |
   8 |  Import-Module SqlServer
     |  ~~~~~~~~~~~~~~~~~~~~~~~
DECLARE @name SYSNAME = 'mi-*********';
DECLARE @id UNIQUEIDENTIFIER = '*********-8298-402d-9ee5-89333184ad33';

-- Convert the guid to the right type
DECLARE @castId NVARCHAR(MAX) = CONVERT(VARCHAR(MAX), CONVERT (VARBINARY(16), @id), 1);

-- Construct command: CREATE USER [@name] WITH SID = @castId, TYPE = E;
DECLARE @cmd NVARCHAR(MAX) = N'CREATE USER [' + @name + '] WITH SID = ' + @castId + ', TYPE = E;'
EXEC (@cmd);
     | The module to process 'SqlServer.psm1', listed in field
     | 'ModuleToProcess/RootModule' of module manifest

-- Assign roles to the new user
DECLARE @role1 NVARCHAR(MAX) = N'ALTER ROLE db_owner ADD MEMBER [' + @name + ']';
EXEC (@role1);

     | '/root/.local/share/powershell/Modules/SqlServer/22.4.5.1/SqlServer.psd1' was not processed because no valid module was found in any module directory.

WARNING: Resulting JSON is truncated as serialization has exceeded the set depth of 2.

Appears to be using SqlServer PowerShell module version 22.4.5.1, as referenced in the report above. This appears to be the only component that has changed for us - as all versions of Aspire and Azd are unchanged.