From 7e15e8b9286683dae214d02b0e7480348a2a8935 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:19:51 +0000 Subject: [PATCH 1/3] Initial plan From c6946b0c875a790a1492db1a4612d9021e7ce33a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:36:25 +0000 Subject: [PATCH 2/3] [Resource] Preserve bicep snapshot expressions Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com> --- .../azure/cli/command_modules/resource/custom.py | 2 +- .../resource/tests/latest/test_resource_bicep.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 1ae23ddf37f..cecad1b0b24 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -4651,7 +4651,7 @@ def snapshot_bicep_file(cmd, file, mode=None, tenant_id=None, subscription_id=No args += ["--location", location] if resource_group: args += ["--resource-group", resource_group] - if deployment_name: + if deployment_name and not re.fullmatch(r'azurecli\d+\.\d+', deployment_name): args += ["--deployment-name", deployment_name] output = run_bicep_command(cmd.cli_ctx, args) diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py index 5ed92fac0ee..c3a91775674 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py @@ -330,6 +330,19 @@ def test_snapshot_bicep_file_passes_minimum_args( bicep_version_check_mock.assert_called_once_with(self.cli_ctx, "0.41.2") run_bicep_command_mock.assert_called_once_with(self.cli_ctx, ["snapshot", "main.bicepparam"]) + @mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command") + @mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to") + @mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation") + def test_snapshot_bicep_file_ignores_generated_deployment_name( + self, ensure_bicep_installation_mock, bicep_version_check_mock, run_bicep_command_mock + ): + bicep_version_check_mock.return_value = True + run_bicep_command_mock.return_value = "" + + snapshot_bicep_file(self.cmd, "main.bicepparam", deployment_name="azurecli123.456789") + + run_bicep_command_mock.assert_called_once_with(self.cli_ctx, ["snapshot", "main.bicepparam"]) + @mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command") @mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to") @mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation") From 2aa42913bac17934fe4991d648313079d056569b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Aug 2026 16:37:30 +0000 Subject: [PATCH 3/3] [Resource] Cover generated snapshot deployment names Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com> --- .../azure/cli/command_modules/resource/custom.py | 4 +++- .../resource/tests/latest/test_resource_bicep.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 cecad1b0b24..8ab6ed157a5 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -62,6 +62,8 @@ logger = get_logger(__name__) +_CLI_GENERATED_DEPLOYMENT_NAME_PATTERN = re.compile(r'azurecli\d+\.\d+') + RPAAS_APIS = {'microsoft.datadog': '/subscriptions/{subscriptionId}/providers/Microsoft.Datadog/agreements/default?api-version=2020-02-01-preview', 'microsoft.confluent': '/subscriptions/{subscriptionId}/providers/Microsoft.Confluent/agreements/default?api-version=2020-03-01-preview'} @@ -4651,7 +4653,7 @@ def snapshot_bicep_file(cmd, file, mode=None, tenant_id=None, subscription_id=No args += ["--location", location] if resource_group: args += ["--resource-group", resource_group] - if deployment_name and not re.fullmatch(r'azurecli\d+\.\d+', deployment_name): + if deployment_name and not _CLI_GENERATED_DEPLOYMENT_NAME_PATTERN.fullmatch(deployment_name): args += ["--deployment-name", deployment_name] output = run_bicep_command(cmd.cli_ctx, args) diff --git a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py index c3a91775674..a6dfcb91a30 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py @@ -343,6 +343,21 @@ def test_snapshot_bicep_file_ignores_generated_deployment_name( run_bicep_command_mock.assert_called_once_with(self.cli_ctx, ["snapshot", "main.bicepparam"]) + @mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command") + @mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to") + @mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation") + def test_snapshot_bicep_file_passes_similarly_named_deployment_name( + self, ensure_bicep_installation_mock, bicep_version_check_mock, run_bicep_command_mock + ): + bicep_version_check_mock.return_value = True + run_bicep_command_mock.return_value = "" + + snapshot_bicep_file(self.cmd, "main.bicepparam", deployment_name="azurecli123") + + run_bicep_command_mock.assert_called_once_with( + self.cli_ctx, ["snapshot", "main.bicepparam", "--deployment-name", "azurecli123"] + ) + @mock.patch("azure.cli.command_modules.resource.custom.run_bicep_command") @mock.patch("azure.cli.command_modules.resource.custom.bicep_version_greater_than_or_equal_to") @mock.patch("azure.cli.command_modules.resource.custom.ensure_bicep_installation")