Skip to content

Commit 4b07d0f

Browse files
authored
add support for workspace UAMI (Azure#19390)
1 parent aeff6d5 commit 4b07d0f

File tree

9 files changed

+214
-14
lines changed

9 files changed

+214
-14
lines changed

src/Synapse/Synapse/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Updated `New-AzSynapseWorkspace` and `Update-AzSynapseWorkspace` to support for user assigned managed identity (UAMI) by `-UserAssignedIdentityAction` and `-UserAssignedIdentityId`
2223
* Added EnablePublicNetworkAccess parameter to `New-AzureSynapseWorkspace` and `Update-AzSynapseWorkspace`
2324

2425
## Version 1.6.0

src/Synapse/Synapse/Commands/ManagementCommands/Workspace/NewAzureSynapseWorkspace.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Microsoft.Azure.Commands.Common.Exceptions;
2424
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2525
using static Microsoft.Azure.Commands.Synapse.Models.SynapseConstants;
26+
using System.Collections.Generic;
2627

2728
namespace Microsoft.Azure.Commands.Synapse
2829
{
@@ -98,6 +99,10 @@ public class NewAzureSynapseWorkspace : SynapseManagementCmdletBase
9899
[ValidateNotNull]
99100
public bool EnablePublicNetworkAccess { get; set; }
100101

102+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.UserAssignedIdentityId)]
103+
[ValidateNotNull]
104+
public List<string> UserAssignedIdentityId { get; set; }
105+
101106
public override void ExecuteCmdlet()
102107
{
103108
try
@@ -132,10 +137,6 @@ public override void ExecuteCmdlet()
132137
var createParams = new Workspace
133138
{
134139
Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true),
135-
Identity = new ManagedIdentity
136-
{
137-
Type = ResourceIdentityType.SystemAssigned
138-
},
139140
DefaultDataLakeStorage = new DataLakeStorageAccountDetails
140141
{
141142
AccountUrl = defaultDataLakeStorageAccountUrl,
@@ -159,8 +160,21 @@ public override void ExecuteCmdlet()
159160
}
160161
} : null,
161162
WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null,
162-
PublicNetworkAccess = this.IsParameterBound(c => c.EnablePublicNetworkAccess) ? (this.EnablePublicNetworkAccess? PublicNetworkAccess.Enabled : PublicNetworkAccess.Disabled): null
163+
PublicNetworkAccess = this.IsParameterBound(c => c.EnablePublicNetworkAccess) ? (this.EnablePublicNetworkAccess? PublicNetworkAccess.Enabled : PublicNetworkAccess.Disabled): null,
164+
Identity = this.IsParameterBound(c => c.UserAssignedIdentityId) ? new ManagedIdentity
165+
{
166+
Type = ResourceIdentityType.SystemAssignedUserAssigned,
167+
UserAssignedIdentities = new Dictionary<string, UserAssignedManagedIdentity>()
168+
} :
169+
new ManagedIdentity
170+
{
171+
Type = ResourceIdentityType.SystemAssigned
172+
}
163173
};
174+
if (this.IsParameterBound(c => c.UserAssignedIdentityId))
175+
{
176+
UserAssignedIdentityId?.ForEach(identityId => createParams.Identity.UserAssignedIdentities.Add(identityId, new UserAssignedManagedIdentity()));
177+
}
164178

165179
if (ShouldProcess(Name, string.Format(Resources.CreatingSynapseWorkspace, this.ResourceGroupName, this.Name)))
166180
{

src/Synapse/Synapse/Commands/ManagementCommands/Workspace/UpdateAzureSynapseWorkspace.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
using Microsoft.WindowsAzure.Commands.Common;
2424
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2525
using System.Collections;
26+
using System.Collections.Generic;
27+
using System.Linq;
2628
using System.Management.Automation;
2729
using static Microsoft.Azure.Commands.Synapse.Models.SynapseConstants;
2830
using SecureString = System.Security.SecureString;
@@ -80,6 +82,13 @@ public class UpdateAzureSynapseWorkspace : SynapseManagementCmdletBase
8082
[Parameter(Mandatory = false, HelpMessage = HelpMessages.GitRepository)]
8183
[ValidateNotNull]
8284
public PSWorkspaceRepositoryConfiguration GitRepository { get; set; }
85+
86+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.UserAssignedIdentityAction)]
87+
public SynapseConstants.UserAssignedManagedIdentityActionType UserAssignedIdentityAction { get; set; }
88+
89+
[Parameter(Mandatory = false, HelpMessage = HelpMessages.UserAssignedIdentityId)]
90+
[ValidateNotNull]
91+
public List<string> UserAssignedIdentityId { get; set; }
8392

8493
[Parameter(Mandatory = false, HelpMessage = HelpMessages.PublicNetworkAccess)]
8594
[ValidateNotNull]
@@ -127,7 +136,7 @@ public override void ExecuteCmdlet()
127136
WorkspacePatchInfo patchInfo = new WorkspacePatchInfo();
128137
patchInfo.Tags = this.IsParameterBound(c => c.Tag) ? TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true) : TagsConversionHelper.CreateTagDictionary(this.InputObject?.Tags, validate:true);
129138
patchInfo.SqlAdministratorLoginPassword = this.IsParameterBound(c => c.SqlAdministratorLoginPassword) ? this.SqlAdministratorLoginPassword.ConvertToString() : null;
130-
patchInfo.ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : this.InputObject?.ManagedVirtualNetworkSettings?.ToSdkObject();
139+
patchInfo.ManagedVirtualNetworkSettings = this.IsParameterBound(c => c.ManagedVirtualNetwork) ? this.ManagedVirtualNetwork?.ToSdkObject() : this.InputObject?.ManagedVirtualNetworkSettings?.ToSdkObject();
131140
string encrptionKeyName = this.IsParameterBound(c => c.EncryptionKeyName) ? this.EncryptionKeyName : this.InputObject?.Encryption?.CustomerManagedKeyDetails?.Key?.Name;
132141
patchInfo.Encryption = !string.IsNullOrEmpty(encrptionKeyName) ? new EncryptionDetails
133142
{
@@ -142,6 +151,47 @@ public override void ExecuteCmdlet()
142151
patchInfo.WorkspaceRepositoryConfiguration = this.IsParameterBound(c => c.GitRepository) ? this.GitRepository.ToSdkObject() : null;
143152
patchInfo.PublicNetworkAccess = this.IsParameterBound(c => c.EnablePublicNetworkAccess) ? (this.EnablePublicNetworkAccess ? PublicNetworkAccess.Enabled : PublicNetworkAccess.Disabled): existingWorkspace.PublicNetworkAccess;
144153

154+
if ((!this.IsParameterBound(c => c.UserAssignedIdentityAction) && this.IsParameterBound(c => c.UserAssignedIdentityId))
155+
|| ((this.IsParameterBound(c => c.UserAssignedIdentityAction) && !this.IsParameterBound(c => c.UserAssignedIdentityId))))
156+
{
157+
throw new AzPSInvalidOperationException(Resources.FailedToValidateUserAssignedIdentityParameter);
158+
}
159+
160+
if (this.IsParameterBound(c => c.UserAssignedIdentityAction) && this.IsParameterBound(c => c.UserAssignedIdentityId))
161+
{
162+
patchInfo.Identity = existingWorkspace.Identity;
163+
patchInfo.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned;
164+
if (patchInfo.Identity.UserAssignedIdentities == null)
165+
{
166+
patchInfo.Identity.UserAssignedIdentities = new Dictionary<string, UserAssignedManagedIdentity>();
167+
}
168+
169+
if (this.UserAssignedIdentityAction == SynapseConstants.UserAssignedManagedIdentityActionType.Add)
170+
{
171+
UserAssignedIdentityId.Where(identity => !patchInfo.Identity.UserAssignedIdentities.ContainsKey(identity))?.ForEach(
172+
item => patchInfo.Identity.UserAssignedIdentities.Add(item, new UserAssignedManagedIdentity()));
173+
}
174+
else if (this.UserAssignedIdentityAction == SynapseConstants.UserAssignedManagedIdentityActionType.Remove)
175+
{
176+
UserAssignedIdentityId.Where(identity => patchInfo.Identity.UserAssignedIdentities.ContainsKey(identity))?.ForEach(
177+
item => patchInfo.Identity.UserAssignedIdentities[item] = null);
178+
}
179+
else if (this.UserAssignedIdentityAction == SynapseConstants.UserAssignedManagedIdentityActionType.Set)
180+
{
181+
patchInfo.Identity.UserAssignedIdentities.Where(identity => !UserAssignedIdentityId.Contains(identity.Key))?.ForEach(
182+
item => patchInfo.Identity.UserAssignedIdentities[item.Key] = null);
183+
184+
UserAssignedIdentityId.Where(identity => !patchInfo.Identity.UserAssignedIdentities.ContainsKey(identity))?.ForEach(
185+
item => patchInfo.Identity.UserAssignedIdentities.Add(item, new UserAssignedManagedIdentity()));
186+
}
187+
188+
if (patchInfo.Identity.UserAssignedIdentities.All(identity => identity.Value == null))
189+
{
190+
patchInfo.Identity.Type = ResourceIdentityType.SystemAssigned;
191+
patchInfo.Identity.UserAssignedIdentities = null;
192+
}
193+
}
194+
145195
if (ShouldProcess(this.Name, string.Format(Resources.UpdatingSynapseWorkspace, this.Name, this.ResourceGroupName)))
146196
{
147197
var workspace = new PSSynapseWorkspace(SynapseAnalyticsClient.UpdateWorkspace(

src/Synapse/Synapse/Common/HelpMessages.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public static class HelpMessages
4848

4949
public const string PublicNetworkAccess = "Enable or Disable public network access to workspace. Possible values include: 'Enabled', 'Disabled'";
5050

51+
public const string UserAssignedIdentityAction =
52+
@"Action must be specified when you add/remove/set user assigned managed identities for workspace.
53+
The supported actions are:
54+
Add
55+
Remove
56+
Set
57+
Add means to add user assigned managed identities for workspace, Remove means to remove user assigned managed identities from workspace, Set can be used when you want to add and remove user assigned managed identities at the same time, current identities will be coverd by specified ones.";
58+
59+
public const string UserAssignedIdentityId = "User assigned managed identity Id for workspace.";
60+
5161
public const string RepositoryType = "Select the repository type that you want to use to store your artifacts for this Synapse Analytics workspace, the type include DevOps and GitHub.";
5262

5363
public const string HostName = "GitHub Enterprise host name. For example: https://github.mydomain.com";

src/Synapse/Synapse/Models/SynapseConstants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ public enum PackageActionType
307307
Add,
308308
Remove
309309
}
310+
public enum UserAssignedManagedIdentityActionType
311+
{
312+
Add,
313+
Remove,
314+
Set
315+
}
310316

311317
public class PublicNetworkAccess
312318
{

src/Synapse/Synapse/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Synapse/Synapse/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,4 +830,7 @@ Failed: {2}.</value>
830830
<data name="SettingSynapseLinkConnection" xml:space="preserve">
831831
<value>Setting link connection '{0}' in workspace '{1}'.</value>
832832
</data>
833+
<data name="FailedToValidateUserAssignedIdentityParameter" xml:space="preserve">
834+
<value>-UserAssignedIdentityAction and -UserAssignedIdentityId must be specified at the same time or neither of them should be.</value>
835+
</data>
833836
</root>

src/Synapse/Synapse/help/New-AzSynapseWorkspace.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ New-AzSynapseWorkspace -ResourceGroupName <String> -Name <String> -Location <Str
1818
-SqlAdministratorLoginCredential <PSCredential> [-ManagedVirtualNetwork <PSManagedVirtualNetworkSettings>]
1919
[-EncryptionKeyName <String>] [-EncryptionKeyIdentifier <String>] [-AsJob]
2020
[-ManagedResourceGroupName <String>] [-GitRepository <PSWorkspaceRepositoryConfiguration>]
21-
[-EnablePublicNetworkAccess <Boolean>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
22-
[<CommonParameters>]
21+
[-EnablePublicNetworkAccess <Boolean>] [-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>]
22+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2323
```
2424

2525
## DESCRIPTION
@@ -66,6 +66,20 @@ New-AzSynapseWorkspace -ResourceGroupName ContosoResourceGroup -Name ContosoWork
6666

6767
This command creates a Synapse Analytics workspace named ContosoWorkspace that uses the ContosoAdlGenStorage Data Store, in the resource group named ContosoResourceGroup. And the workspace is connected to a Git Repository called ContosoRepo.
6868

69+
### Example 5
70+
```powershell
71+
$password = ConvertTo-SecureString "Password123!" -AsPlainText -Force
72+
$creds = New-Object System.Management.Automation.PSCredential ("ContosoUser", $password)
73+
$uamis = Get-AzUserAssignedIdentity -ResourceGroupName ContosoResourceGroup
74+
$uamilist = New-Object System.Collections.Generic.List[string]
75+
foreach($uami in $uamis){
76+
$uamilist.Add($uami.Id)
77+
}
78+
New-AzSynapseWorkspace -ResourceGroupName ContosoResourceGroup -Name ContosoWorkspace -Location northeurope -DefaultDataLakeStorageAccountName ContosoAdlGen2Storage -DefaultDataLakeStorageFilesystem ContosoFileSystem -SqlAdministratorLoginCredential $creds -UserAssignedIdentityId $uamilist
79+
```
80+
81+
This command creates a Synapse Analytics workspace named ContosoWorkspace that uses the ContosoAdlGenStorage Data Store, in the resource group named ContosoResourceGroup, and add user assigned managed identities that get from ResourceGroup ContosoResourceGroup to workspace.
82+
6983
## PARAMETERS
7084

7185
### -AsJob
@@ -293,6 +307,21 @@ Accept pipeline input: True (ByPropertyName)
293307
Accept wildcard characters: False
294308
```
295309
310+
### -UserAssignedIdentityId
311+
User assigned managed identity Id for workspace.
312+
313+
```yaml
314+
Type: System.Collections.Generic.List`1[System.String]
315+
Parameter Sets: (All)
316+
Aliases:
317+
318+
Required: False
319+
Position: Named
320+
Default value: None
321+
Accept pipeline input: False
322+
Accept wildcard characters: False
323+
```
324+
296325
### -Confirm
297326
Prompts you for confirmation before running the cmdlet.
298327

src/Synapse/Synapse/help/Update-AzSynapseWorkspace.md

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@ Updates a Synapse Analytics workspace.
1717
Update-AzSynapseWorkspace [-ResourceGroupName <String>] -Name <String> [-Tag <Hashtable>]
1818
[-SqlAdministratorLoginPassword <SecureString>] [-ManagedVirtualNetwork <PSManagedVirtualNetworkSettings>]
1919
[-EncryptionKeyName <String>] [-GitRepository <PSWorkspaceRepositoryConfiguration>]
20-
[-EnablePublicNetworkAccess <Boolean>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
21-
[-Confirm] [<CommonParameters>]
20+
[-EnablePublicNetworkAccess <Boolean>] [-UserAssignedIdentityAction <UserAssignedManagedIdentityActionType>]
21+
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-AsJob]
22+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2223
```
2324

2425
### SetByInputObjectParameterSet
2526
```
2627
Update-AzSynapseWorkspace -InputObject <PSSynapseWorkspace> [-Tag <Hashtable>]
2728
[-SqlAdministratorLoginPassword <SecureString>] [-ManagedVirtualNetwork <PSManagedVirtualNetworkSettings>]
2829
[-EncryptionKeyName <String>] [-GitRepository <PSWorkspaceRepositoryConfiguration>]
29-
[-EnablePublicNetworkAccess <Boolean>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
30-
[-Confirm] [<CommonParameters>]
30+
[-EnablePublicNetworkAccess <Boolean>] [-UserAssignedIdentityAction <UserAssignedManagedIdentityActionType>]
31+
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-AsJob]
32+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3133
```
3234

3335
### SetByResourceIdParameterSet
3436
```
3537
Update-AzSynapseWorkspace -ResourceId <String> [-Tag <Hashtable>]
3638
[-SqlAdministratorLoginPassword <SecureString>] [-ManagedVirtualNetwork <PSManagedVirtualNetworkSettings>]
3739
[-EncryptionKeyName <String>] [-GitRepository <PSWorkspaceRepositoryConfiguration>]
38-
[-EnablePublicNetworkAccess <Boolean>] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
39-
[-Confirm] [<CommonParameters>]
40+
[-EnablePublicNetworkAccess <Boolean>] [-UserAssignedIdentityAction <UserAssignedManagedIdentityActionType>]
41+
[-UserAssignedIdentityId <System.Collections.Generic.List`1[System.String]>] [-AsJob]
42+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
4043
```
4144

4245
## DESCRIPTION
@@ -81,6 +84,45 @@ Update-AzSynapseWorkspace -Name ContosoWorkspace -EnablePublicNetworkAccess $Tru
8184

8285
This commands updates the specififed Azure Synapse Analytics workspace to enable public network access.
8386

87+
### Example 6
88+
```powershell
89+
$uamis = Get-AzUserAssignedIdentity -ResourceGroupName bigdataqa
90+
$uamilist = New-Object System.Collections.Generic.List[string]
91+
foreach($uami in $uamis){
92+
$uamilist.Add($uami.Id)
93+
}
94+
95+
Update-AzSynapseWorkspace -Name ContosoWorkspace -UserAssignedIdentityAction Add -UserAssignedIdentityId $uamilist
96+
```
97+
98+
This commands updates workspace to add user assigned managed identites in $uamilist.
99+
100+
### Example 7
101+
```powershell
102+
$uamis = Get-AzUserAssignedIdentity -ResourceGroupName bigdataqa
103+
$uamilist = New-Object System.Collections.Generic.List[string]
104+
foreach($uami in $uamis){
105+
$uamilist.Add($uami.Id)
106+
}
107+
108+
Update-AzSynapseWorkspace -Name ContosoWorkspace -UserAssignedIdentityAction Remove -UserAssignedIdentityId $uamilist[0]
109+
```
110+
111+
This commands removes user assigned managed identites $uamilist[0] from workspace.
112+
113+
### Example 8
114+
```powershell
115+
$uamis = Get-AzUserAssignedIdentity -ResourceGroupName bigdataqa
116+
$uamilist = New-Object System.Collections.Generic.List[string]
117+
foreach($uami in $uamis){
118+
$uamilist.Add($uami.Id)
119+
}
120+
121+
Update-AzSynapseWorkspace -Name ContosoWorkspace -UserAssignedIdentityAction Set -UserAssignedIdentityId $uamilist
122+
```
123+
124+
This commands updates workspace with user assigned managed identites $uamilist that will cover current identities.
125+
84126
## PARAMETERS
85127

86128
### -AsJob
@@ -263,6 +305,42 @@ Accept pipeline input: False
263305
Accept wildcard characters: False
264306
```
265307
308+
### -UserAssignedIdentityAction
309+
Action must be specified when you add/remove/set user assigned managed identities for workspace.
310+
The supported actions are:
311+
Add
312+
Remove
313+
Set
314+
Add means to add user assigned managed identities for workspace, Remove means to remove user assigned managed identities from workspace, Set can be used when you want to add and remove user assigned managed identities at the same time.
315+
316+
```yaml
317+
Type: Microsoft.Azure.Commands.Synapse.Models.SynapseConstants+UserAssignedManagedIdentityActionType
318+
Parameter Sets: (All)
319+
Aliases:
320+
Accepted values: Add, Remove, Set
321+
322+
Required: False
323+
Position: Named
324+
Default value: None
325+
Accept pipeline input: False
326+
Accept wildcard characters: False
327+
```
328+
329+
### -UserAssignedIdentityId
330+
User assigned managed identity Id for workspace.
331+
332+
```yaml
333+
Type: System.Collections.Generic.List`1[System.String]
334+
Parameter Sets: (All)
335+
Aliases:
336+
337+
Required: False
338+
Position: Named
339+
Default value: None
340+
Accept pipeline input: False
341+
Accept wildcard characters: False
342+
```
343+
266344
### -Confirm
267345
Prompts you for confirmation before running the cmdlet.
268346

0 commit comments

Comments
 (0)