Skip to content

Commit 6a7019b

Browse files
committed
Don't set properties on existing Azure SQL server resources
1 parent f3b72d5 commit 6a7019b

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,6 @@ private static void CreateSqlServer(
205205
{
206206
var resource = SqlServer.FromExisting(identifier);
207207
resource.Name = name;
208-
resource.Administrators = new ServerExternalAdministrator()
209-
{
210-
AdministratorType = SqlAdministratorType.ActiveDirectory,
211-
IsAzureADOnlyAuthenticationEnabled = true,
212-
Sid = principalIdParameter,
213-
Login = principalNameParameter,
214-
TenantId = BicepFunction.GetSubscription().TenantId
215-
};
216208
return resource;
217209
},
218210
(infrastructure) =>
@@ -248,7 +240,10 @@ private static void CreateSqlServer(
248240
// the principalType.
249241
var principalTypeParameter = new ProvisioningParameter(AzureBicepResource.KnownParameters.PrincipalType, typeof(string));
250242
infrastructure.Add(principalTypeParameter);
251-
sqlServer.Administrators.PrincipalType = principalTypeParameter;
243+
if (!sqlServer.IsExistingResource)
244+
{
245+
sqlServer.Administrators.PrincipalType = principalTypeParameter;
246+
}
252247

253248
infrastructure.Add(new SqlFirewallRule("sqlFirewallRule_AllowAllIps")
254249
{

tests/Aspire.Hosting.Azure.Tests/ExistingAzureResourceTests.cs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,15 +1122,6 @@ param existingResourceName string
11221122
11231123
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' existing = {
11241124
name: existingResourceName
1125-
properties: {
1126-
administrators: {
1127-
administratorType: 'ActiveDirectory'
1128-
login: principalName
1129-
sid: principalId
1130-
tenantId: subscription().tenantId
1131-
azureADOnlyAuthentication: true
1132-
}
1133-
}
11341125
}
11351126
11361127
resource sqlFirewallRule_AllowAllAzureIps 'Microsoft.Sql/servers/firewallRules@2021-11-01' = {
@@ -1190,16 +1181,6 @@ param principalType string
11901181
11911182
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' existing = {
11921183
name: existingResourceName
1193-
properties: {
1194-
administrators: {
1195-
administratorType: 'ActiveDirectory'
1196-
principalType: principalType
1197-
login: principalName
1198-
sid: principalId
1199-
tenantId: subscription().tenantId
1200-
azureADOnlyAuthentication: true
1201-
}
1202-
}
12031184
}
12041185
12051186
resource sqlFirewallRule_AllowAllAzureIps 'Microsoft.Sql/servers/firewallRules@2021-11-01' = {
@@ -1372,13 +1353,13 @@ public async Task SupportsExistingAzureApplicationInsightsWithResourceGroup()
13721353
var expectedBicep = """
13731354
@description('The location for the resource(s) to be deployed.')
13741355
param location string = resourceGroup().location
1375-
1356+
13761357
param existingResourceName string
1377-
1358+
13781359
resource appInsights 'Microsoft.Insights/components@2020-02-02' existing = {
13791360
name: existingResourceName
13801361
}
1381-
1362+
13821363
output appInsightsConnectionString string = appInsights.properties.ConnectionString
13831364
""";
13841365

@@ -1419,17 +1400,17 @@ public async Task SupportsExistingAzureOpenAIWithResourceGroup()
14191400
var expectedBicep = """
14201401
@description('The location for the resource(s) to be deployed.')
14211402
param location string = resourceGroup().location
1422-
1403+
14231404
param existingResourceName string
1424-
1405+
14251406
param principalType string
1426-
1407+
14271408
param principalId string
1428-
1409+
14291410
resource openAI 'Microsoft.CognitiveServices/accounts@2024-10-01' existing = {
14301411
name: existingResourceName
14311412
}
1432-
1413+
14331414
resource openAI_CognitiveServicesOpenAIContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
14341415
name: guid(openAI.id, principalId, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'a001fd3d-188f-4b5d-821b-7da978bf7442'))
14351416
properties: {
@@ -1439,7 +1420,7 @@ param principalId string
14391420
}
14401421
scope: openAI
14411422
}
1442-
1423+
14431424
resource mymodel 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = {
14441425
name: 'mymodel'
14451426
properties: {

0 commit comments

Comments
 (0)