dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.79k stars 450 forks source link

New Azure SQL API has different naming conventions than Aspire 8 #6474

Open melotic opened 1 day ago

melotic commented 1 day ago

Is there an existing issue for this?

Describe the bug

In Aspire 8, I had this code to provision an Azure SQL Server & Database:

var sqlDatabase = builder.AddSqlServer("sql-server")
    .WithDataVolume()
    .PublishAsAzureSqlDatabase((_, _, _, sqlDatabases) =>
    {
        foreach (var db in sqlDatabases)
        {
            db.Properties.Sku = new SqlSku("S0") { Tier = "Standard" };
        }
    })
    .AddDatabase("evadexdb");

Upgrading to .NET 9.0-rc, and Aspire, I changed this code in accordance to the What's New docs:

builder.Services.Configure<AzureResourceOptions>(options => options.ProvisioningContext.PropertyResolvers.Insert(0, new AspireV8ResourceNamePropertyResolver()));

var sqlDatabase = builder.AddAzureSqlServer("sql-server")
    .RunAsContainer(x => x.WithLifetime(ContainerLifetime.Persistent))
    .AddDatabase("evadexdb");

However, this has changed the naming on sql-server to sql_server, which is not a valid Azure SQL server name. azd provision returns this (version 1.10.3):

ERROR: deployment failed: error deploying infrastructure: deploying to subscription:

Deployment Error Details:
InvalidServerName: The server name 'sql_serverxr4o3alsj2qhw' cannot be empty or null. The server name can only be made up of lowercase letters 'a'-'z', the numbers 0-9 and the hyphen. The hyphen may not lead or trail in the server name. Please fix the server name and retry. Please contact Microsoft support if the issue persists.

TraceID: 489[42](https://github.com/PhantomSecurityGroup/EvadeX.Web/actions/runs/11490357271/job/31981252826#step:10:43)d2d159dc8f50fab7182f10d0124
Error: Process completed with exit code 1.

Taking a look at the different bison files generated:

Aspire 8

resource sqlServer_XEivP4Ku5 'Microsoft.Sql/servers@2020-11-01-preview' = {
  name: toLower(take('sql-server${uniqueString(resourceGroup().id)}', 24))
  location: location
  tags: {
    'aspire-resource-name': 'sql-server'
  }
  properties: {
    version: '12.0'
    minimalTlsVersion: '1.2'
    publicNetworkAccess: 'Enabled'
    administrators: {
      administratorType: 'ActiveDirectory'
      login: principalName
      sid: principalId
      tenantId: subscription().tenantId
      azureADOnlyAuthentication: true
    }
  }
}

Aspire 9 (w/ new Azure SQL API)

resource sql_server 'Microsoft.Sql/servers@2021-11-01' = {
  name: toLower(take('sql_server${uniqueString(resourceGroup().id)}', 24))
  location: location
  properties: {
    administrators: {
      administratorType: 'ActiveDirectory'
      login: principalName
      sid: principalId
      tenantId: subscription().tenantId
      azureADOnlyAuthentication: true
    }
    minimalTlsVersion: '1.2'
    publicNetworkAccess: 'Enabled'
    version: '12.0'
  }
  tags: {
    'aspire-resource-name': 'sql-server'
  }
}

Expected Behavior

The previous name in Azure was sql-serverxr4o3alsj2qhw and should remain that, not sql_serverxr4o3alsj2qhw.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

PS D:\source\PhantomSecurityGroup\EvadeX.Web> dotnet --info
.NET SDK:
 Version:           9.0.100-rc.2.24474.11
 Commit:            315e1305db
 Workload version:  9.0.100-manifests.0c3a5b37
 MSBuild version:   17.12.0-preview-24473-03+fea15fbd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26120
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.11.35327.3
   Manifest Version:    8.2.1/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.1\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0-rc.2.24473.5
  Architecture: x64
  Commit:       990ebf52fc

.NET SDKs installed:
  8.0.403 [C:\Program Files\dotnet\sdk]
  9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  D:\source\PhantomSecurityGroup\EvadeX.Web\global.json

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

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

Anything else?

Using the deprecated API resolves the issue.

davidfowl commented 15 hours ago

@eerhardt this looks important to fix for 9.

cc @joperezr