Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down Expand Up @@ -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:
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,34 @@ 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")
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")
Expand Down
Loading