Skip to content

[ARM] az ts: Capture subscription id from template resource id#31896

Merged
a0x1ab merged 9 commits intoAzure:devfrom
a0x1ab:dev
Aug 6, 2025
Merged

[ARM] az ts: Capture subscription id from template resource id#31896
a0x1ab merged 9 commits intoAzure:devfrom
a0x1ab:dev

Conversation

@a0x1ab
Copy link
Copy Markdown
Member

@a0x1ab a0x1ab commented Jul 31, 2025

Related command
ts

Description

Testing Guide
Can be tested using:

  • az ts show -s {template-spec-id} ...
  • az ts update -s {template-spec-id} ...
  • az ts delete -s {template-spec-id} ...
  • az ts export -s {template-spec-id} ...

Current tests already assess this functionality

This checklist is used to make sure that common guidelines for a pull request are followed.

a0x1ab added 6 commits July 29, 2025 22:45
Update template spec operations to extract and use the subscription ID from the resource ID if provided. Add tests to verify correct handling of subscription IDs in show, update, delete, and export commands for template specs.
Deleted test cases and YAML recordings related to template spec operations using a fake subscription ID. These tests were unnecessary as the functionality is already tested in other tests.
Removed redundant subscription_id variable assignments in template spec-related functions. Now, subscription_id is passed directly from parsed resource ID when template_spec is provided, improving code clarity and reducing duplication.
@a0x1ab a0x1ab added this to the September 2025 (2025-09-02) milestone Jul 31, 2025
@a0x1ab a0x1ab self-assigned this Jul 31, 2025
Copilot AI review requested due to automatic review settings July 31, 2025 10:14
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jul 31, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️latest
️✔️3.12
️✔️3.9

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jul 31, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Jul 31, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Copy Markdown
Contributor

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 enhances the az ts (template spec) commands to dynamically extract and use the subscription ID from the template spec resource ID when provided. This eliminates the need for users to explicitly specify the subscription parameter when working with template specs from different subscriptions.

  • Updates the template spec client factory to accept an optional subscription_id parameter
  • Modifies show, update, delete, and export commands to parse subscription ID from template spec resource ID
  • Improves user experience by automatically setting the correct subscription context

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
_client_factory.py Adds optional subscription_id parameter to template spec client factory
custom.py Updates template spec commands to extract subscription ID from resource ID and pass to client factory

Comment thread src/azure-cli/azure/cli/command_modules/resource/custom.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/resource/custom.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/resource/custom.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/resource/custom.py Outdated
@ReaNAiveD
Copy link
Copy Markdown
Member

Could you please add or update relevant test cases to ensure the changes work correctly in our test tenant?

@a0x1ab
Copy link
Copy Markdown
Member Author

a0x1ab commented Aug 1, 2025

Could you please add or update relevant test cases to ensure the changes work correctly in our test tenant?

Thank you @ReaNAiveD for the review! Regarding test cases, I had initially added one for each sub-command but have noticed that my changes are already tested withing the current show, update, export and delete tests for the template specs. Example:

self.cmd('ts update -s {template_spec_id} --display-name {display_name} --description {description} --yes', checks=[
self.check('name', self.kwargs['template_spec_name']),
self.check('description', self.kwargs['description'].replace('"', '')),
self.check('displayName', self.kwargs['display_name'].replace('"', ''))
])
self.cmd('ts update -s {template_spec_version_id} --version-description {version_description} --yes', checks=[
self.check('name', '1.0'),
self.check('description', self.kwargs['version_description'].replace('"', '')),
self.check('linkedTemplates', None)
])
provides test coverage over the changes here: https://github.com/Azure/azure-cli/pull/31896/files#diff-08239753041d380a8aedfebe24dff21ce54e0f09255f514e932bc2bac4fab75bR67 and adjacent modifications to make the sub fetching dynamic as it later in the same test function executes checks to ensure the correct changes have been made

@ReaNAiveD
Copy link
Copy Markdown
Member

ReaNAiveD commented Aug 1, 2025

Could you please add or update relevant test cases to ensure the changes work correctly in our test tenant?

Thank you @ReaNAiveD for the review! Regarding test cases, I had initially added one for each sub-command but have noticed that my changes are already tested withing the current show, update, export and delete tests for the template specs. Example:

self.cmd('ts update -s {template_spec_id} --display-name {display_name} --description {description} --yes', checks=[
self.check('name', self.kwargs['template_spec_name']),
self.check('description', self.kwargs['description'].replace('"', '')),
self.check('displayName', self.kwargs['display_name'].replace('"', ''))
])
self.cmd('ts update -s {template_spec_version_id} --version-description {version_description} --yes', checks=[
self.check('name', '1.0'),
self.check('description', self.kwargs['version_description'].replace('"', '')),
self.check('linkedTemplates', None)
])

provides test coverage over the changes here: https://github.com/Azure/azure-cli/pull/31896/files#diff-08239753041d380a8aedfebe24dff21ce54e0f09255f514e932bc2bac4fab75bR67 and adjacent modifications to make the sub fetching dynamic as it later in the same test function executes checks to ensure the correct changes have been made

Aditya explains the reason offline.
Since the customer was able to run the command successfully with a different subscription using the --subscription parameter and we don't have a previous test for cross-subscription scenarios, perhaps we don't need to add a test for this condition, especially if it's difficult to test resources across different subscriptions.

@bebound
Copy link
Copy Markdown
Contributor

bebound commented Aug 1, 2025

Since this pr add the ability to omit the --subscription option in cross-sub scenario, it's better to add a test to ensure it works as expected.

@necusjz
Copy link
Copy Markdown
Member

necusjz commented Aug 1, 2025

useful snniepts for cross-sub testing:

@zhoxing-ms zhoxing-ms changed the title [Resource] az ts: Capture subscription id from template resource id [ARM] az ts: Capture subscription id from template resource id Aug 1, 2025
a0x1ab added 2 commits August 5, 2025 21:51
Introduces new test cases to validate update, show, delete and export operations for template specs using an auxiliary subscription.
@a0x1ab a0x1ab added ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group and removed Template labels Aug 5, 2025
@a0x1ab a0x1ab requested review from necusjz and shenglol August 6, 2025 00:05
@a0x1ab a0x1ab merged commit f6848fc into Azure:dev Aug 6, 2025
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az ts show uses default subscription even when a full resource id is provided

7 participants