Skip to content

Commit 8ed586f

Browse files
krivi37Stefan Krivokapic
andauthored
[SQL] Add 'AuthenticationMetadata' option to New and Set AzSqlInstance cmdlets (#25700)
* Added test and create option * Updated examples * Updated changelog * Updated description of new parameter * Changed indents * Update ChangeLog.md --------- Co-authored-by: Stefan Krivokapic <[email protected]>
1 parent 141ed93 commit 8ed586f

File tree

10 files changed

+3750
-2913
lines changed

10 files changed

+3750
-2913
lines changed

src/Sql/Sql.Test/ScenarioTests/ManagedInstanceCrudScenarioTests.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ function Test-CreateManagedInstance
3838
$timezoneId = "Central Europe Standard Time"
3939
$proxyOverride = "Proxy"
4040
$backupStorageRedundancy = "Local"
41+
$authenticationMetadata = "Paired"
42+
$defaultAuthenticationMetadata = "AzureAD"
4143

4244
try
4345
{
4446
# With SKU name specified
4547
$job = New-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstanceName `
4648
-Location $rg.Location -AdministratorCredential $credentials -SubnetId $defaultParams.subnet `
4749
-LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Vcore $vCore -SkuName $skuName -Collation $collation `
48-
-TimezoneId $timezoneId -PublicDataEndpointEnabled -ProxyOverride $proxyOverride -BackupStorageRedundancy $backupStorageRedundancy -AsJob
50+
-TimezoneId $timezoneId -PublicDataEndpointEnabled -ProxyOverride $proxyOverride -BackupStorageRedundancy $backupStorageRedundancy -AuthenticationMetadata $authenticationMetadata -AsJob
4951
$job | Wait-Job
5052
$managedInstance1 = $job.Output
5153

@@ -66,7 +68,8 @@ function Test-CreateManagedInstance
6668
Assert-AreEqual $managedInstance1.CurrentBackupStorageRedundancy $backupStorageRedundancy
6769
Assert-AreEqual $managedInstance1.BackupStorageRedundancy $backupStorageRedundancy
6870
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName
69-
Assert-NotNull $managedInstance1.DnsZone
71+
Assert-NotNull $managedInstance1.DnsZone
72+
Assert-AreEqual $managedInstance1.AuthenticationMetadata $authenticationMetadata
7073

7174
$edition = "GeneralPurpose"
7275
$computeGeneration = "Gen5"
@@ -90,8 +93,8 @@ function Test-CreateManagedInstance
9093
Assert-AreEqual $managedInstance1.LicenseType $licenseType
9194
Assert-AreEqual $managedInstance1.VCores $vCore
9295
Assert-AreEqual $managedInstance1.StorageSizeInGB $storageSizeInGB
93-
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName
94-
Assert-AreEqual $managedInstance1.DnsZone $originalDnsZone
96+
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName
97+
Assert-AreEqual $managedInstance1.DnsZone $originalDnsZone
9598

9699
## Get-AzSqlInstance test ##
97100
############################
@@ -106,6 +109,7 @@ function Test-CreateManagedInstance
106109
Assert-AreEqual $managedInstance1.VCores $resp1.VCores
107110
Assert-AreEqual $managedInstance1.StorageSizeInGB $resp1.StorageSizeInGB
108111
Assert-AreEqual $false $managedInstance1.ZoneRedundant
112+
Assert-AreEqual $managedInstance1.AuthenticationMetadata $defaultAuthenticationMetadata
109113

110114
$all = Get-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name *
111115
Assert-AreEqual 2 $all.Count
@@ -281,16 +285,18 @@ function Test-SetManagedInstance
281285
$targetSubnetResourceId = "/subscriptions/8313371e-0879-428e-b1da-6353575a9192/resourceGroups/CustomerExperienceTeam_RG/providers/Microsoft.Network/virtualNetworks/vnet-mi-tooling/subnets/ManagedInstance2"
282286
$generalPurpose = "GeneralPurpose"
283287
$businessCritical = "BusinessCritical"
288+
$authenticationMetadata = "Windows"
284289

285290
$managedInstance1 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
286-
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Force
291+
-AdministratorPassword $credentials.Password -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -Force -AuthenticationMetadata $authenticationMetadata
287292

288293
Assert-AreEqual $managedInstance1.ManagedInstanceName $managedInstance.ManagedInstanceName
289294
Assert-AreEqual $managedInstance1.AdministratorLogin $managedInstance.AdministratorLogin
290295
Assert-AreEqual $managedInstance1.LicenseType $licenseType
291296
Assert-AreEqual $managedInstance1.VCores $managedInstance.VCores
292297
Assert-AreEqual $managedInstance1.StorageSizeInGB $storageSizeInGB
293-
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName
298+
Assert-StartsWith ($managedInstance1.ManagedInstanceName + ".") $managedInstance1.FullyQualifiedDomainName]
299+
Assert-AreEqual $managedInstance1.AuthenticationMetadata $authenticationMetadata
294300

295301
# Test using piping
296302
$credentials = Get-ServerCredential

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests/TestCreateManagedInstance.json

Lines changed: 1498 additions & 526 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests/TestSetManagedInstance.json

Lines changed: 2064 additions & 2355 deletions
Large diffs are not rendered by default.

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Added IsGeneralPurposeV2 and StorageIOps fields to the model of the managed instance so that it displays information about GPv2 instances that are returned by `Get-AzSqlInstance`.
2626
* Added new cmdlet `Set-AzSqlDatabaseReplicationLink` for updating replication link type
2727
* Updated `Get-AzSqlDatabaseReplicationLink` to use the new sdk
28+
* Added new parameter AuthenticationMetadata to `New-AzSqlInstance` and `Set-AzSqlInstance`
2829

2930
## Version 5.1.0
3031
* Added cross-subscription support for `Copy-AzSqlInstanceDatabase`, `Move-AzSqlInstanceDatabase`

src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,15 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
437437
HelpMessage = "Determines how much Storage IOps to associate with instance.",
438438
ParameterSetName = NewByEditionAndComputeGenerationParameterSet)]
439439
public int StorageIOps { get; set; }
440+
441+
/// <summary>
442+
/// Specifies weather or not Managed Instance is freemium
443+
/// </summary>
444+
[Parameter(Mandatory = false,
445+
HelpMessage = "Preferred metadata to use for authentication of synced on-prem users. Default is AzureAD.")]
446+
[ValidateSet("AzureAD", "Paired", "Windows")]
447+
[PSArgumentCompleter("AzureAD", "Paired", "Windows")]
448+
public string AuthenticationMetadata { get; set; }
440449

441450
/// <summary>
442451
/// Overriding to add warning message
@@ -614,7 +623,8 @@ public override void ExecuteCmdlet()
614623
// For non-MI database, we can just pass in 0 and the server will treat 0 as default.
615624
// However this is (currently) not the case for MI. We need to convert the 0 to null
616625
// here in client before sending to the server.
617-
StorageIOps = SqlSkuUtils.ValueIfNonZero(this.StorageIOps)
626+
StorageIOps = SqlSkuUtils.ValueIfNonZero(this.StorageIOps),
627+
AuthenticationMetadata = this.AuthenticationMetadata
618628
});
619629
return newEntity;
620630
}

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
298298
HelpMessage = "Determines how much Storage IOps to associate with instance.")]
299299
public int? StorageIOps { get; set; }
300300

301+
/// <summary>
302+
/// Specifies weather or not Managed Instance is freemium
303+
/// </summary>
304+
[Parameter(Mandatory = false,
305+
HelpMessage = "Preferred metadata to use for authentication of synced on-prem users. Default is AzureAD.")]
306+
[ValidateSet("AzureAD", "Paired", "Windows")]
307+
[PSArgumentCompleter("AzureAD", "Paired", "Windows")]
308+
public string AuthenticationMetadata { get; set; }
309+
301310
/// <summary>
302311
/// Get the instance to update
303312
/// </summary>
@@ -394,6 +403,7 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
394403
// This is due to the fact that this update might have a target edition that does not use this parameter.
395404
// If the target edition uses the parameter, the current value will get picked up later in the update process.
396405
updateData[0].StorageIOps = this.StorageIOps;
406+
updateData[0].AuthenticationMetadata = this.AuthenticationMetadata ?? updateData[0].AuthenticationMetadata;
397407

398408
return updateData;
399409
}

src/Sql/Sql/ManagedInstance/Model/AzureSqlManagedInstanceModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,11 @@ public class AzureSqlManagedInstanceModel
206206
/// Possible values include: &#39;Enabled&#39;, &#39;Disabled&#39;
207207
/// </summary>
208208
public string ExternalGovernanceStatus { get; set; }
209+
210+
/// <summary>
211+
/// Gets or sets the authentication metadata mode of the managed instance.
212+
/// Possible values include: &#39;AzureAD&#39;, &#39;Paired&#39;, &#39;Windows&#39;
213+
/// </summary>
214+
public string AuthenticationMetadata { get; set; }
209215
}
210216
}

src/Sql/Sql/ManagedInstance/Services/AzureSqlManagedInstanceAdapter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanc
177177
DatabaseFormat = model.DatabaseFormat,
178178
PricingModel = model.PricingModel,
179179
IsGeneralPurposeV2 = model.IsGeneralPurposeV2,
180-
StorageIOps = model.StorageIOps
180+
StorageIOps = model.StorageIOps,
181+
AuthenticationMetadata = model.AuthenticationMetadata
181182
});
182183

183184
return CreateManagedInstanceModelFromResponse(resp);
@@ -299,6 +300,7 @@ private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromRespon
299300
managedInstance.DatabaseFormat = resp.DatabaseFormat;
300301
managedInstance.PricingModel = resp.PricingModel;
301302
managedInstance.ExternalGovernanceStatus = resp.ExternalGovernanceStatus;
303+
managedInstance.AuthenticationMetadata = resp.AuthenticationMetadata;
302304

303305
return managedInstance;
304306
}

src/Sql/Sql/help/New-AzSqlInstance.md

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ New-AzSqlInstance [-Name] <String> [-ResourceGroupName] <String> [-Administrator
2424
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-IdentityType <String>] [-AsJob]
2525
[-Force] [-EnableActiveDirectoryOnlyAuthentication] [-ExternalAdminName <String>] [-ExternalAdminSID <Guid>]
2626
[-ZoneRedundant] [-ServicePrincipalType <String>] [-DatabaseFormat <String>] [-PricingModel <String>]
27-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf]
28-
[-Confirm] [<CommonParameters>]
27+
[-AuthenticationMetadata <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
28+
[<CommonParameters>]
2929
```
3030

3131
### NewByInstancePoolParentObjectParameterSet
@@ -38,8 +38,8 @@ New-AzSqlInstance [-InstancePool] <AzureSqlInstancePoolModel> [-Name] <String>
3838
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-IdentityType <String>] [-AsJob]
3939
[-Force] [-EnableActiveDirectoryOnlyAuthentication] [-ExternalAdminName <String>] [-ExternalAdminSID <Guid>]
4040
[-ZoneRedundant] [-ServicePrincipalType <String>] [-DatabaseFormat <String>] [-PricingModel <String>]
41-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf]
42-
[-Confirm] [<CommonParameters>]
41+
[-AuthenticationMetadata <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
42+
[<CommonParameters>]
4343
```
4444

4545
### NewByInstancePoolResourceIdParameterSet
@@ -52,8 +52,8 @@ New-AzSqlInstance [-InstancePoolResourceId] <String> [-Name] <String> [-Administ
5252
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-IdentityType <String>] [-AsJob]
5353
[-Force] [-EnableActiveDirectoryOnlyAuthentication] [-ExternalAdminName <String>] [-ExternalAdminSID <Guid>]
5454
[-ZoneRedundant] [-ServicePrincipalType <String>] [-DatabaseFormat <String>] [-PricingModel <String>]
55-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf]
56-
[-Confirm] [<CommonParameters>]
55+
[-AuthenticationMetadata <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
56+
[<CommonParameters>]
5757
```
5858

5959
### NewBySkuNameParameterSetParameter
@@ -67,8 +67,8 @@ New-AzSqlInstance [-Name] <String> [-ResourceGroupName] <String> [-Administrator
6767
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-IdentityType <String>] [-AsJob]
6868
[-Force] [-EnableActiveDirectoryOnlyAuthentication] [-ExternalAdminName <String>] [-ExternalAdminSID <Guid>]
6969
[-ZoneRedundant] [-ServicePrincipalType <String>] [-DatabaseFormat <String>] [-PricingModel <String>]
70-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf]
71-
[-Confirm] [<CommonParameters>]
70+
[-AuthenticationMetadata <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
71+
[<CommonParameters>]
7272
```
7373

7474
## DESCRIPTION
@@ -360,7 +360,7 @@ TenantId : f553829b-6d84-481b-86a9-42db57c1dc73
360360
AzureADOnlyAuthentication : True
361361
```
362362

363-
This command creates a new zone - redundant instance
363+
This command creates a new instance with external administrator properties and Microsoft Entra-only authentication enabled.
364364

365365
### Example 10: Create a new zone - redundant instance
366366
```powershell
@@ -389,7 +389,7 @@ InstancePoolName :
389389
ZoneRedundant : true
390390
```
391391

392-
This command creates a new instance with external administrator properties and Microsoft Entra-only authentication enabled.
392+
This command creates a new zone - redundant instance.
393393

394394
### Example 11: Create a new instance with TDE CMK
395395
```powershell
@@ -448,7 +448,53 @@ DatabaseFormat : AlwaysUpToDate
448448
PricingModel : Regular
449449
```
450450

451-
This command creates a new instance with external administrator properties and Microsoft Entra-only authentication enabled.
451+
This command creates a new instance with database format and pricing model specified.
452+
453+
### Example 10: Create a new managed instance which uses Windows authentication metadata mode
454+
```powershell
455+
New-AzSqlInstance -Name managedInstance1 -ResourceGroupName ResourceGroup01 -Location westcentralus -AdministratorCredential (Get-Credential) -SubnetId "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Network/virtualNetworks/vnet_name/subnets/subnet_name" -LicenseType LicenseIncluded -StorageSizeInGB 1024 -VCore 16 -SkuName GP_Gen5 -AuthenticationMetadata Windows
456+
```
457+
458+
```output
459+
Location : westcentralus
460+
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Sql/managedInstances/managedInstance1
461+
ResourceGroupName : resourcegroup01
462+
ManagedInstanceName : managedInstance1
463+
Tags :
464+
Identity :
465+
Sku : Microsoft.Azure.Management.Internal.Resources.Models.Sku
466+
FullyQualifiedDomainName : managedInstance1.xxxxxxxxxxxx.database.windows.net
467+
AdministratorLogin : adminLogin1
468+
AdministratorPassword :
469+
SubnetId : subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Network/virtualNetworks/vnet_name/subnets/subnet_name
470+
LicenseType : LicenseIncluded
471+
VCores : 16
472+
StorageSizeInGB : 1024
473+
Collation : SQL_Latin1_General_CP1_CI_AS
474+
PublicDataEndpointEnabled : False
475+
ProxyOverride : Default
476+
TimezoneId : UTC
477+
DnsZonePartner :
478+
DnsZone : ad35cna0mw
479+
InstancePoolName :
480+
MinimalTlsVersion : None
481+
BackupStorageRedundancy : Geo
482+
RequestedBackupStorageRedundancy : Geo
483+
CurrentBackupStorageRedundancy : Geo
484+
MaintenanceConfigurationId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Maintenance/
485+
publicMaintenanceConfigurations/SQL_Default
486+
Administrators :
487+
PrimaryUserAssignedIdentityId :
488+
KeyId :
489+
ZoneRedundant : False
490+
ServicePrincipal :
491+
DatabaseFormat : SQLServer2022
492+
PricingModel : Regular
493+
ExternalGovernanceStatus : Disabled
494+
AuthenticationMetadata : Windows
495+
```
496+
497+
This command creates a new managed instance which uses Windows metadata for authentication of synced users.
452498

453499
## PARAMETERS
454500

@@ -497,6 +543,22 @@ Accept pipeline input: False
497543
Accept wildcard characters: False
498544
```
499545
546+
### -AuthenticationMetadata
547+
Preferred metadata to use for authentication of synced on-prem users. Default is AzureAD.
548+
549+
```yaml
550+
Type: System.String
551+
Parameter Sets: (All)
552+
Aliases:
553+
Accepted values: AzureAD, Paired, Windows
554+
555+
Required: False
556+
Position: Named
557+
Default value: None
558+
Accept pipeline input: False
559+
Accept wildcard characters: False
560+
```
561+
500562
### -BackupStorageRedundancy
501563
The Backup storage redundancy used to store backups for the Sql Azure Managed Instance. Options are: Local, Zone and Geo
502564
@@ -1105,5 +1167,3 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
11051167
## NOTES
11061168
11071169
## RELATED LINKS
1108-
1109-
## RELATED LINKS

0 commit comments

Comments
 (0)