Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,19 @@ public void TestInVMAccessControlProfileVersion()
TestRunner.RunTestScript("Test-InVMAccessControlProfileVersion");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGalleryWithSystemAssignedIdentity()
{
TestRunner.RunTestScript("Test-GalleryWithSystemAssignedIdentity");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdateGalleryWithSystemAssignedIdentity()
{
TestRunner.RunTestScript("Test-UpdateGalleryWithSystemAssignedIdentity");
}

}
}
76 changes: 75 additions & 1 deletion src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1224,4 +1224,78 @@ function Test-InVMAccessControlProfileVersion
# Cleanup
Clean-ResourceGroup $rgname;
}
}
}
<#
.SYNOPSIS
Tests New-AzGallery with system-assigned managed identity
#>
function Test-GalleryWithSystemAssignedIdentity
{
# Setup
$rgname = Get-ComputeTestResourceName;
$galleryName = 'gallery' + $rgname;

try
{
# Common
[string]$loc = Get-ComputeVMLocation;
$loc = $loc.Replace(' ', '');
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Create gallery with system-assigned identity
$gallery = New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $loc -EnableSystemAssignedIdentity;

Assert-NotNull $gallery;
Assert-NotNull $gallery.Identity;
Assert-AreEqual "SystemAssigned" $gallery.Identity.Type.ToString();

# Retrieve gallery and verify identity is preserved
$gallery = Get-AzGallery -ResourceGroupName $rgname -Name $galleryName;
Assert-NotNull $gallery.Identity;
Assert-AreEqual "SystemAssigned" $gallery.Identity.Type.ToString();
}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}

<#
.SYNOPSIS
Tests Update-AzGallery with system-assigned managed identity
#>
function Test-UpdateGalleryWithSystemAssignedIdentity
{
# Setup
$rgname = Get-ComputeTestResourceName;
$galleryName = 'gallery' + $rgname;

try
{
# Common
[string]$loc = Get-ComputeVMLocation;
$loc = $loc.Replace(' ', '');
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Create gallery without identity
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $loc;

# Update gallery to add system-assigned identity
$gallery = Update-AzGallery -ResourceGroupName $rgname -Name $galleryName -EnableSystemAssignedIdentity;

Assert-NotNull $gallery;
Assert-NotNull $gallery.Identity;
Assert-AreEqual "SystemAssigned" $gallery.Identity.Type.ToString();

# Verify identity via Get
$gallery = Get-AzGallery -ResourceGroupName $rgname -Name $galleryName;
Assert-NotNull $gallery.Identity;
Assert-AreEqual "SystemAssigned" $gallery.Identity.Type.ToString();
}
finally
{
# Cleanup
Remove-AzResourceGroup -Name $rgname -Force -ErrorAction SilentlyContinue;
}
}
3 changes: 3 additions & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

-->
## Upcoming Release
* Added `-EnableSystemAssignedIdentity` and `-UserAssignedIdentity` parameters to `New-AzGallery` cmdlet to support managed identities when creating an Azure Compute Gallery
* Added `-EnableSystemAssignedIdentity` and `-UserAssignedIdentity` parameters to `Update-AzGallery` cmdlet to support updating managed identities on an Azure Compute Gallery
* Updated `Get-AzGallery` output object to include the `Identity` property of type `GalleryIdentity`

## Version 11.4.0
* Added `-DiskIOPSReadWrite` and `-DiskMBpsReadWrite` parameters to `Add-AzVMDataDisk` cmdlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ public override void ExecuteCmdlet()
gallery.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
}

bool hasSystemAssigned = this.IsParameterBound(c => c.EnableSystemAssignedIdentity) && this.EnableSystemAssignedIdentity.IsPresent;
bool hasUserAssigned = this.IsParameterBound(c => c.UserAssignedIdentity) && this.UserAssignedIdentity.Length > 0;

if (hasSystemAssigned || hasUserAssigned)
{
gallery.Identity = new GalleryIdentity();

if (hasSystemAssigned && hasUserAssigned)
{
gallery.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned;
}
else if (hasSystemAssigned)
{
gallery.Identity.Type = ResourceIdentityType.SystemAssigned;
}
else
{
gallery.Identity.Type = ResourceIdentityType.UserAssigned;
}

if (hasUserAssigned)
{
gallery.Identity.UserAssignedIdentities = new Dictionary<string, UserAssignedIdentitiesValue>();
foreach (var id in this.UserAssignedIdentity)
{
gallery.Identity.UserAssignedIdentities[id] = new UserAssignedIdentitiesValue();
}
}
}

var result = GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
var psObject = new PSGallery();
Expand Down Expand Up @@ -169,6 +198,17 @@ public override void ExecuteCmdlet()
HelpMessage = "Gets or sets the prefix of the gallery name that will be displayed publicly. Visible to all users.")]
public string PublicNamePrefix { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Enables system-assigned managed identity on the gallery.")]
public SwitchParameter EnableSystemAssignedIdentity { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The list of user-assigned managed identity resource IDs to associate with the gallery. The resource IDs are in the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.")]
public string[] UserAssignedIdentity { get; set; }

}

[Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Gallery", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)]
Expand Down Expand Up @@ -242,6 +282,39 @@ public override void ExecuteCmdlet()
gallery.Tags = this.Tag.Cast<DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value);
}

bool hasSystemAssigned = this.IsParameterBound(c => c.EnableSystemAssignedIdentity) && this.EnableSystemAssignedIdentity.IsPresent;
bool hasUserAssigned = this.IsParameterBound(c => c.UserAssignedIdentity) && this.UserAssignedIdentity.Length > 0;

if (hasSystemAssigned || hasUserAssigned)
{
if (gallery.Identity == null)
{
gallery.Identity = new GalleryIdentity();
}

if (hasSystemAssigned && hasUserAssigned)
{
gallery.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned;
}
else if (hasSystemAssigned)
{
gallery.Identity.Type = ResourceIdentityType.SystemAssigned;
}
else
{
gallery.Identity.Type = ResourceIdentityType.UserAssigned;
}

if (hasUserAssigned)
{
gallery.Identity.UserAssignedIdentities = new Dictionary<string, UserAssignedIdentitiesValue>();
foreach (var id in this.UserAssignedIdentity)
{
gallery.Identity.UserAssignedIdentities[id] = new UserAssignedIdentitiesValue();
}
}
}

if (this.IsParameterBound(c => c.Permission))
{
if (gallery.SharingProfile == null)
Expand Down Expand Up @@ -371,7 +444,7 @@ public override void ExecuteCmdlet()
}
else
{
GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
result = GalleriesClient.CreateOrUpdate(resourceGroupName, galleryName, gallery);
}
var psObject = new PSGallery();
ComputeAutomationAutoMapperProfile.Mapper.Map<Gallery, PSGallery>(result, psObject);
Expand Down Expand Up @@ -496,5 +569,16 @@ public override void ExecuteCmdlet()
ValueFromPipelineByPropertyName = true,
HelpMessage = "Gets or sets the prefix of the gallery name that will be displayed publicly. Visible to all users.")]
public string PublicNamePrefix { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Enables system-assigned managed identity on the gallery.")]
public SwitchParameter EnableSystemAssignedIdentity { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The list of user-assigned managed identity resource IDs to associate with the gallery. The resource IDs are in the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.")]
public string[] UserAssignedIdentity { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Compute/Compute/Generated/Models/PSGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public string ResourceGroupName
public string Location { get; set; }
public IDictionary<string, string> Tags { get; set; }
public SharingProfile SharingProfile { get; set; }
public GalleryIdentity Identity { get; set; }

}
}
48 changes: 48 additions & 0 deletions src/Compute/Compute/help/New-AzGallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Create a gallery.
New-AzGallery [-ResourceGroupName] <String> [-Name] <String> [-AsJob] [-Location] <String>
[-Description <String>] [-Tag <Hashtable>] [-Permission <String>] [-PublisherUri <String>]
[-PublisherContact <String>] [-Eula <String>] [-PublicNamePrefix <String>]
[-EnableSystemAssignedIdentity] [-UserAssignedIdentity <String[]>]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```
Expand All @@ -39,6 +40,21 @@ New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $location

Create a gallery with Direct Sharing enabled.

### Example 3
```powershell
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $location -EnableSystemAssignedIdentity
```

Create a gallery with a system-assigned managed identity.

### Example 4
```powershell
$uid = Get-AzUserAssignedIdentity -ResourceGroupName $rgname -Name $identityName
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $location -UserAssignedIdentity $uid.Id
```

Create a gallery with a user-assigned managed identity.

## PARAMETERS

### -AsJob
Expand Down Expand Up @@ -86,6 +102,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -EnableSystemAssignedIdentity
Enables system-assigned managed identity on the gallery.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Eula
Gets or sets end-user license agreement for community gallery image.

Expand Down Expand Up @@ -221,6 +252,21 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -UserAssignedIdentity
The list of user-assigned managed identity resource IDs to associate with the gallery. The resource IDs are in the form '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.

```yaml
Type: System.String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

Expand Down Expand Up @@ -261,6 +307,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

### System.Collections.Hashtable

### System.String[]

## OUTPUTS

### Microsoft.Azure.Commands.Compute.Automation.Models.PSGallery
Expand Down
Loading
Loading