Skip to content

[Resources] Added expand functionality to GetAzureResource and GetAzureResourceGroup #28161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

a0x1ab
Copy link
Member

@a0x1ab a0x1ab commented Jul 10, 2025

Description

PR pertains to the following issues:

  1. Enable $expand for List Resources (Get-AzureRmResource or Find-AzureRmResource) #5814
  2. [Feature]: Get-AzResourceGroup: Include createdTime and changedTime, at least optionally #27865

This PR introduces the following changes:

  1. Resources and ResourceGroup endpoints now additionally request the $expand parameter to provide users with createdTime and changedTime properties for the GetAzureResource and GetAzureResourceGroup cmdlets respectively
  2. Added testing for the both the GetAzureResource and GetAzureResourceGroup cmdlets to ensure the expanded properties are returned as expected
  3. Re-generated shared models and extensions

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

a0x1ab and others added 12 commits June 19, 2025 15:25
Test-AzResourceGroupDeployment output an empty warning as the conditionals were not accounting for all cases
Co-authored-by: Vincent Dai <23257217+vidai-msft@users.noreply.github.com>
Introduces new filter models (GenericResourceFilterWithExpand, ResourceGroupFilterWithExpand) and updates SDK interfaces and implementations to support the $expand query parameter for retrieving createdTime and changedTime on resources and resource groups. Updates related cmdlets and tests to validate the new properties.
@a0x1ab a0x1ab self-assigned this Jul 10, 2025
Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@a0x1ab a0x1ab changed the title [Resources] Added expand functionality to GetAzureResource and GetAzureResourceGroup [Resources] Added expand functionality to GetAzureResource and GetAzureResourceGroup Jul 10, 2025
@a0x1ab a0x1ab marked this pull request as ready for review July 10, 2025 02:09
@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 02:09
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds $expand support to the GetAzureResource and GetAzureResourceGroup cmdlets so that CreatedTime and ChangedTime are returned, and updates models, SDK clients, and tests accordingly.

  • Extend $expand parameter usage in OData queries and direct GET calls to include createdTime,changedTime
  • Augment PSResource/PSResourceGroup models and extensions with CreatedTime/ChangedTime
  • Add and update tests to verify expanded properties and update SDK transforms and changelog

Reviewed Changes

Copilot reviewed 10 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Resources/Resources/ChangeLog.md Documented new expand functionality and fixed warnings
src/Resources/Resources.Test/ResourceGroups/GetAzureResourceGroupCommandTests.cs Added tests for timestamps on resource group cmdlet
src/Resources/Resources.Test/Resource/GetAzureResourceCommandTests.cs Updated tests to use expanded model and assert timestamps
src/Resources/Resources.Test/Models.ResourceGroups/ResourceClientTests.cs Updated mock setups to include $expand parameter
src/Resources/Resources.Management.Sdk/README.md Insert SDK readme transforms for $expand
src/Resources/ResourceManager/SdkModels/ResourceGroups/PSResourceGroup.cs Added CreatedTime and ChangedTime properties
src/Resources/ResourceManager/SdkExtensions/NewResourcesExtensions.cs Populate new timestamp properties in extension method
src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs Change ListResources/ListByResourceGroup to use expanded filter
src/Resources/ResourceManager/SdkClient/NewResourceManagerSdkClient.cs Update FilterResourceGroups to set Expand and call GET with expand
src/Resources/ResourceManager/Implementation/Resource/GetAzureResourceCmdlet.cs Switch to expanded filter and set Expand in cmdlet
Comments suppressed due to low confidence (2)

src/Resources/Resources/ChangeLog.md:23

  • [nitpick] Add a space before the issue references, e.g. ...GetAzureResourceGroup [#5814] [#27865], for consistent formatting.
* Added functionality for cmdlet `GetAzureResource` and `GetAzureResourceGroup`[#5814][#27865]

src/Resources/Resources.Test/Resource/GetAzureResourceCommandTests.cs:76

  • [nitpick] Consider adding a test for the list (subscription-level) path of the Get-AzureResource cmdlet to verify CreatedTime and ChangedTime are returned when no ResourceId is provided.
        public void GetsResourcesById()

a0x1ab and others added 8 commits July 10, 2025 12:16
Co-authored-by: Vincent Dai <23257217+vidai-msft@users.noreply.github.com>
Introduces new filter models (GenericResourceFilterWithExpand, ResourceGroupFilterWithExpand) and updates SDK interfaces and implementations to support the $expand query parameter for retrieving createdTime and changedTime on resources and resource groups. Updates related cmdlets and tests to validate the new properties.
Fixed changelog
Deleted the GetsResourceGroupsWithTimestamps test, which duplicated the logic of an existing test. This reduces redundancy and simplifies the test suite.
@YanaXu
Copy link
Contributor

YanaXu commented Jul 10, 2025

Please fix the test errors. Don't forget to submit the recording files.

Copy link

This PR was labeled "needs-revision" because it has unresolved review comments or CI failures.
Please resolve all open review comments and make sure all CI checks are green. Refer to our guide to troubleshoot common CI failures.

@@ -171,7 +171,8 @@ private void RunSimpleCmdlet()
tagValue: null,
filter: this.ODataQuery);

var odataQuery = new Rest.Azure.OData.ODataQuery<GenericResourceFilter>(expression);
var odataQuery = new Rest.Azure.OData.ODataQuery<Azure.Management.Resources.Models.GenericResourceFilterWithExpand>(expression);
odataQuery.Expand = "createdTime,changedTime";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to add a ExpandProperty parameter, and the validate set is the set of the valid property values, and default value can be "createdTime,changedTime"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I think it will be better to set Expand false by default. Only show the expand informations when user want them.

@YanaXu
Copy link
Contributor

YanaXu commented Jul 14, 2025

Hi @a0x1ab , please check wyunchi-ms's comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants