Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,6 @@ private static void CreateSqlServer(
{
var resource = SqlServer.FromExisting(identifier);
resource.Name = name;
resource.Administrators = new ServerExternalAdministrator()
{
AdministratorType = SqlAdministratorType.ActiveDirectory,
IsAzureADOnlyAuthenticationEnabled = true,
Sid = principalIdParameter,
Login = principalNameParameter,
TenantId = BicepFunction.GetSubscription().TenantId
};
return resource;
},
(infrastructure) =>
Expand Down Expand Up @@ -248,7 +240,10 @@ private static void CreateSqlServer(
// the principalType.
var principalTypeParameter = new ProvisioningParameter(AzureBicepResource.KnownParameters.PrincipalType, typeof(string));
infrastructure.Add(principalTypeParameter);
sqlServer.Administrators.PrincipalType = principalTypeParameter;
if (!sqlServer.IsExistingResource)
{
sqlServer.Administrators.PrincipalType = principalTypeParameter;
}

infrastructure.Add(new SqlFirewallRule("sqlFirewallRule_AllowAllIps")
{
Expand Down
37 changes: 9 additions & 28 deletions tests/Aspire.Hosting.Azure.Tests/ExistingAzureResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,15 +1122,6 @@ param existingResourceName string

resource sqlServer 'Microsoft.Sql/servers@2021-11-01' existing = {
name: existingResourceName
properties: {
administrators: {
administratorType: 'ActiveDirectory'
login: principalName
sid: principalId
tenantId: subscription().tenantId
azureADOnlyAuthentication: true
}
}
}

resource sqlFirewallRule_AllowAllAzureIps 'Microsoft.Sql/servers/firewallRules@2021-11-01' = {
Expand Down Expand Up @@ -1190,16 +1181,6 @@ param principalType string

resource sqlServer 'Microsoft.Sql/servers@2021-11-01' existing = {
name: existingResourceName
properties: {
administrators: {
administratorType: 'ActiveDirectory'
principalType: principalType
login: principalName
sid: principalId
tenantId: subscription().tenantId
azureADOnlyAuthentication: true
}
}
}

resource sqlFirewallRule_AllowAllAzureIps 'Microsoft.Sql/servers/firewallRules@2021-11-01' = {
Expand Down Expand Up @@ -1372,13 +1353,13 @@ public async Task SupportsExistingAzureApplicationInsightsWithResourceGroup()
var expectedBicep = """
@description('The location for the resource(s) to be deployed.')
param location string = resourceGroup().location

param existingResourceName string

resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: existingResourceName
}

output appInsightsConnectionString string = appInsights.properties.ConnectionString
""";

Expand Down Expand Up @@ -1419,17 +1400,17 @@ public async Task SupportsExistingAzureOpenAIWithResourceGroup()
var expectedBicep = """
@description('The location for the resource(s) to be deployed.')
param location string = resourceGroup().location

param existingResourceName string

param principalType string

param principalId string

resource openAI 'Microsoft.CognitiveServices/accounts@2024-10-01' existing = {
name: existingResourceName
}

resource openAI_CognitiveServicesOpenAIContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(openAI.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442'))
properties: {
Expand All @@ -1439,7 +1420,7 @@ param principalId string
}
scope: openAI
}

resource mymodel 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = {
name: 'mymodel'
properties: {
Expand Down
Loading