Skip to content

[ARM] az group export: Add --export-format to specify the format of the exported template#31667

Merged
zhoxing-ms merged 11 commits intoAzure:devfrom
davidcho23:addDecompileBicep
Jul 10, 2025
Merged

[ARM] az group export: Add --export-format to specify the format of the exported template#31667
zhoxing-ms merged 11 commits intoAzure:devfrom
davidcho23:addDecompileBicep

Conversation

@davidcho23
Copy link
Copy Markdown
Contributor

@davidcho23 davidcho23 commented Jun 18, 2025

Related command

az group export

Description

Adding the output_format parameter to the az group export command so that users can specify whether to export as a json or Bicep template. Providing arm or json as the output_format will export as a json template, and providing bicep will export as a Bicep template. Providing no output_format will default to exporting as a json template.

Testing Guide

az group export will export as a json template
az group export --output_format arm will export as a json template
az group export --output_format json will export as a json template
az group export --output_format bicep will export as a Bicep template

History Notes


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

Copilot AI review requested due to automatic review settings June 18, 2025 15:31
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jun 18, 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

Hi @davidcho23,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

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

azure-client-tools-bot-prd bot commented Jun 18, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️resource
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd group export cmd group export added parameter export_format

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Jun 18, 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>

@microsoft-github-policy-service microsoft-github-policy-service bot added the Auto-Assign Auto assign by bot label Jun 18, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group label Jun 18, 2025
@davidcho23 davidcho23 changed the title [ARM] az group export: Adding output_format for group export [ARM] az group export: Add output_format for group export Jun 18, 2025
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 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-format argument in _params.py
  • Extend export_group_as_template to 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.

Comment thread src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.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/_params.py Outdated
@cceneag
Copy link
Copy Markdown

cceneag commented Jun 18, 2025

我想快😩我努力衝刺
有方式可以跑快一點嗎或是直接提交?
IMG_0002

@yanzhudd
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Comment on lines +538 to +539
c.argument('output_format', options_list=['--output-format'],
help="The format of the exported template. Allowed values: 'json', 'arm', 'bicep'. Defaults to 'json'.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@davidcho23 davidcho23 force-pushed the addDecompileBicep branch 2 times, most recently from a1ca513 to ae192cd Compare July 3, 2025 17:04
@zhoxing-ms zhoxing-ms changed the title [ARM] az group export: Add output_format for group export [ARM] az group export: Add --export-format to specify the format of the exported template Jul 4, 2025
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'.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to declare the default option name

Suggested change
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use the specific error type instead of InvalidArgumentValueError

Suggested change
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'.")
Copy link
Copy Markdown
Contributor

@zhoxing-ms zhoxing-ms Jul 8, 2025

Choose a reason for hiding this comment

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

Could you define an enumeration for the valid values of these parameters?

code example:

c.argument('mode', arg_type=get_enum_type(DeploymentMode, default='incremental'), help='The mode that is used to deploy resources. This value can be either Incremental or Complete. In Incremental mode, resources are deployed without deleting existing resources that are not included in the template. In Complete mode, resources are deployed and existing resources in the resource group that are not included in the template are deleted. Be careful when using Complete mode as you may unintentionally delete resources.')

arg_type=get_enum_type(DeploymentMode, default='incremental')

@davidcho23 davidcho23 force-pushed the addDecompileBicep branch from 5f689fc to 72f838b Compare July 9, 2025 04:45
@davidcho23 davidcho23 force-pushed the addDecompileBicep branch from 72f838b to d77338d Compare July 9, 2025 19:13
@zhoxing-ms zhoxing-ms merged commit a7e596e into Azure:dev Jul 10, 2025
48 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 Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants