Skip to content

Commit

Permalink
Fixed Get-AzResourceGroup on -Id requires Set-AzContext to given subs…
Browse files Browse the repository at this point in the history
…cription first [#21725]
  • Loading branch information
Nickcandy committed May 11, 2023
1 parent 3504d69 commit b636c89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersi

protected override void OnProcessRecord()
{
Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;
this.WriteObject(ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location), true);
String subscriptionId = null;
if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(this.Id)){
Name = ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;
subscriptionId = ResourceIdentifier.FromResourceGroupIdentifier(this.Id).Subscription;
}

this.WriteObject(ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location, subscriptionId), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,10 @@ public virtual PSResourceGroup UpdatePSResourceGroup(PSUpdateResourceGroupParame
/// <param name="tag">The resource group tag.</param>
/// <param name="detailed">Whether the return is detailed or not.</param>
/// <param name="location">The resource group location.</param>
/// <param name="subscriptionId"></param>

/// <returns>The filtered resource groups</returns>
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null)
public virtual List<PSResourceGroup> FilterResourceGroups(string name,Hashtable tag, bool detailed, string location = null, string subscriptionId = null)
{
List<PSResourceGroup> result = new List<PSResourceGroup>();

Expand Down Expand Up @@ -909,6 +911,9 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
{
try
{
if (!String.IsNullOrEmpty(subscriptionId)) {
ResourceManagementClient.SubscriptionId = subscriptionId;
}
PSResourceGroup resourceGroup = ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();
if (string.IsNullOrEmpty(location) || resourceGroup.Location.EqualsAsLocation(location))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void GetsResourcesGroups()
ResourceGroupName = resourceGroupName
};
result.Add(expected);
resourcesClientMock.Setup(f => f.FilterResourceGroups(resourceGroupName, null, false, null)).Returns(result);
resourcesClientMock.Setup(f => f.FilterResourceGroups(resourceGroupName, null, false, null, null)).Returns(result);

cmdlet.Name = resourceGroupName;

Expand All @@ -86,7 +86,7 @@ public void GetsResourcesGroupsById()
ResourceGroupName = resourceGroupName
};
result.Add(expected);
resourcesClientMock.Setup(f => f.FilterResourceGroups(null, null, true, null)).Returns(result);
resourcesClientMock.Setup(f => f.FilterResourceGroups(null, null, true, null, null)).Returns(result);

cmdlet.Id = resourceGroupId;

Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Fixed `New-AzADApplication` when multiple redirect url types are provided. [#21108]
* Fixed `Update-AzADServicePrincipal` when empty array passed for `IdentifierUri` [#21345]
* Fixed an issue where location header was missing in the response from the service for New-AzManagedApplication.
* Fixed `Get-AzResourceGroup` on -Id requires `Set-AzContext` to given subscription first [#21725]

## Version 6.6.1
* Added support for Azure resources deployment with parameters file using Bicep parameters syntax
Expand Down

0 comments on commit b636c89

Please sign in to comment.