diff --git a/src/azure-cli/HISTORY.rst b/src/azure-cli/HISTORY.rst index 25e618f4e24..2f1c7a0cf64 100644 --- a/src/azure-cli/HISTORY.rst +++ b/src/azure-cli/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +**ARM** + +* az group deployment create: Add --handle-extended-json-format to support multiline and comments in json template + **Compute** * vmss create: Add --terminate-notification-time parameters to support terminate scheduled event configurability. diff --git a/src/azure-cli/azure/cli/command_modules/resource/_params.py b/src/azure-cli/azure/cli/command_modules/resource/_params.py index 329cd00574f..6b44f649f8a 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_params.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_params.py @@ -175,6 +175,8 @@ def load_arguments(self, _): with self.argument_context('group deployment create') as c: c.argument('deployment_name', options_list=['--name', '-n'], required=False, help='The deployment name. Default to template file base name') + c.argument('handle_extended_json_format', action='store_true', is_preview=True, + help='Support to handle extended template content including multiline and comments in deployment') with self.argument_context('group deployment operation show') as c: c.argument('operation_ids', nargs='+', help='A list of operation ids to show') diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index e3c3ddd0edf..4e733e0fe29 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -24,7 +24,7 @@ from azure.mgmt.resource.resources.models import GenericResource from azure.cli.core.parser import IncorrectUsageError -from azure.cli.core.util import get_file_json, shell_safe_json_parse, sdk_no_wait +from azure.cli.core.util import get_file_json, read_file_content, shell_safe_json_parse, sdk_no_wait from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType, get_sdk, get_api_version @@ -286,6 +286,120 @@ def _deploy_arm_template_core(cli_ctx, resource_group_name, return sdk_no_wait(no_wait, smc.deployments.create_or_update, resource_group_name, deployment_name, properties) +def _remove_comments_from_json(template): + from jsmin import jsmin + + minified = jsmin(template) + # Get rid of multi-line strings. Note, we are not sending it on the wire rather just extract parameters to prompt for values + result = re.sub(r'"[^"]*?\n[^"]*?(?=2.3.1,<3.0.0', 'fabric~=2.4', + 'jsmin~=2.2.2', 'knack~=0.6,>=0.6.3', 'mock~=2.0', 'paramiko>=2.0.8,<3.0.0',