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
#21765)

* Fixed Get-AzResourceGroup on -Id requires Set-AzContext to given subscription first [#21725]

* Update src/Resources/Resources/ChangeLog.md

Co-authored-by: Yeming Liu <[email protected]>

* revise code

* revise code

---------

Co-authored-by: Yeming Liu <[email protected]>
  • Loading branch information
Nickcandy and isra-fel authored May 15, 2023
1 parent 8c0328a commit b15e4cb
Show file tree
Hide file tree
Showing 4 changed files with 15 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 (ResourceGroupIdParameterSet.Equals(ParameterSetName)){
ResourceIdentifier resourceIdentifier = ResourceIdentifier.FromResourceGroupIdentifier(this.Id);
Name = resourceIdentifier.ResourceGroupName;
subscriptionId = resourceIdentifier.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,9 @@ 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 +910,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` ignored the subscription ID in `-Id` [#21725]

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

0 comments on commit b15e4cb

Please sign in to comment.