[ARM] az group export: Add --export-format to specify the format of the exported template#31667
[ARM] az group export: Add --export-format to specify the format of the exported template#31667zhoxing-ms merged 11 commits intoAzure:devfrom
az group export: Add --export-format to specify the format of the exported template#31667Conversation
️✔️AzureCLI-FullTest
|
|
Hi @davidcho23, |
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| group export | cmd group export added parameter export_format |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
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). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
az group export: Adding output_format for group exportaz group export: Add output_format for group export
There was a problem hiding this comment.
Pull Request Overview
This PR adds an output_format parameter to the az group export command, allowing users to choose between JSON/ARM and Bicep template exports. It updates the CLI’s parameter definitions, implements format branching in the export logic, and adds a Bicep-specific test case.
- Define and register
--output-formatargument in_params.py - Extend
export_group_as_templateto handle JSON/ARM vs. Bicep and API version checks - Add a Bicep export integration test in
test_resource.py
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/latest/test_resource.py | Added test_resource_group_export_output_format_bicep for Bicep output |
| command_modules/resource/custom.py | Extended export_group_as_template with output_format, format logic, and version branching |
| command_modules/resource/_params.py | Registered new output_format CLI argument |
Comments suppressed due to low confidence (2)
src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py:95
- The new 'output_format' parameter supports 'json'/'arm' values (and default JSON behavior), but there are no tests covering those cases. Consider adding tests for JSON and ARM outputs.
@ResourceGroupPreparer(name_prefix='cli_test_rg_scenario')
src/azure-cli/azure/cli/command_modules/resource/custom.py:1671
- The docstring was not updated to mention the new 'output_format' parameter. Please add its description and allowed values.
"""Captures a resource group as a template.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
beb7d05 to
0f1f0c5
Compare
| c.argument('output_format', options_list=['--output-format'], | ||
| help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.") |
There was a problem hiding this comment.
Because this parameter is similar to the global parameter --output and can be confusing, it is recommended to change the parameter name to export_format
a1ca513 to
ae192cd
Compare
az group export: Add output_format for group exportaz group export: Add --export-format to specify the format of the exported template
| c.argument('skip_resource_name_params', action='store_true') | ||
| c.argument('skip_all_params', action='store_true') | ||
| c.argument('resource_ids', nargs='+', options_list='--resource-ids') | ||
| c.argument('export_format', options_list=['--export-format'], help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.") |
There was a problem hiding this comment.
We don't need to declare the default option name
| c.argument('export_format', options_list=['--export-format'], help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.") | |
| c.argument('export_format', help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.") |
| elif export_format.lower() == "bicep": | ||
| export_template_request = ExportTemplateRequest(resources=resources, options=options, output_format="Bicep") | ||
| else: | ||
| raise CLIError('az resource: error: argument --export-format: invalid ExportFormat value: \'%s\'' % export_format) |
There was a problem hiding this comment.
Please use the specific error type instead of InvalidArgumentValueError
| raise CLIError('az resource: error: argument --export-format: invalid ExportFormat value: \'%s\'' % export_format) | |
| raise InvalidArgumentValueError('az resource: error: argument --export-format: invalid ExportFormat value: \'%s\'' % export_format) |
| c.argument('skip_resource_name_params', action='store_true') | ||
| c.argument('skip_all_params', action='store_true') | ||
| c.argument('resource_ids', nargs='+', options_list='--resource-ids') | ||
| c.argument('export_format', help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.") |
There was a problem hiding this comment.
Could you define an enumeration for the valid values of these parameters?
code example:
arg_type=get_enum_type(DeploymentMode, default='incremental')
5f689fc to
72f838b
Compare
72f838b to
d77338d
Compare

Related command
az group exportDescription
Adding the
output_formatparameter to theaz group export commandso that users can specify whether to export as a json or Bicep template. Providing arm or json as theoutput_formatwill export as a json template, and providing bicep will export as a Bicep template. Providing nooutput_formatwill default to exporting as a json template.Testing Guide
az group exportwill export as a json templateaz group export --output_format armwill export as a json templateaz group export --output_format jsonwill export as a json templateaz group export --output_format bicepwill export as a Bicep templateHistory Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.