Skip to content

Commit 46fc028

Browse files
authored
[Compute] az vm/vmss create/update: Add support for setting security type to Standard (#31002)
1 parent f5ab79d commit 46fc028

File tree

8 files changed

+6504
-5134
lines changed

8 files changed

+6504
-5134
lines changed

src/azure-cli/azure/cli/command_modules/vm/_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def load_arguments(self, _):
442442
c.argument('ephemeral_os_disk_placement', arg_type=ephemeral_placement_type,
443443
help='Only applicable when used with `--size`. Allows you to choose the Ephemeral OS disk provisioning location.')
444444
c.argument('enable_hibernation', arg_type=get_three_state_flag(), min_api='2021-03-01', help='The flag that enable or disable hibernation capability on the VM.')
445-
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch"], default=None), min_api='2022-11-01', help='Specify the security type of the virtual machine.')
445+
c.argument('security_type', arg_type=get_enum_type(["TrustedLaunch", "Standard"], default=None), min_api='2022-11-01', help='Specify the security type of the virtual machine.')
446446

447447
with self.argument_context('vm create') as c:
448448
c.argument('name', name_arg_type, validator=_resource_not_exists(self.cli_ctx, 'Microsoft.Compute/virtualMachines'))

src/azure-cli/azure/cli/command_modules/vm/_template_builder.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,12 @@ def _build_storage_profile():
675675

676676
# The `Standard` is used for backward compatibility to allow customers to keep their current behavior
677677
# after changing the default values to Trusted Launch VMs in the future.
678-
from ._constants import COMPATIBLE_SECURITY_TYPE_VALUE
679-
if security_type is not None and security_type != COMPATIBLE_SECURITY_TYPE_VALUE:
678+
if security_type is not None:
680679
vm_properties['securityProfile']['securityType'] = security_type
681680

682-
if enable_secure_boot is not None or enable_vtpm is not None:
681+
from ._constants import COMPATIBLE_SECURITY_TYPE_VALUE
682+
if security_type != COMPATIBLE_SECURITY_TYPE_VALUE and (
683+
enable_secure_boot is not None or enable_vtpm is not None):
683684
vm_properties['securityProfile']['uefiSettings'] = {
684685
'secureBootEnabled': enable_secure_boot,
685686
'vTpmEnabled': enable_vtpm
@@ -1506,11 +1507,12 @@ def build_vmss_resource(cmd, name, computer_name_prefix, location, tags, overpro
15061507

15071508
# The `Standard` is used for backward compatibility to allow customers to keep their current behavior
15081509
# after changing the default values to Trusted Launch VMs in the future.
1509-
from ._constants import COMPATIBLE_SECURITY_TYPE_VALUE
1510-
if security_type is not None and security_type != COMPATIBLE_SECURITY_TYPE_VALUE:
1510+
if security_type is not None:
15111511
security_profile['securityType'] = security_type
15121512

1513-
if enable_secure_boot is not None or enable_vtpm is not None:
1513+
from ._constants import COMPATIBLE_SECURITY_TYPE_VALUE
1514+
if security_type != COMPATIBLE_SECURITY_TYPE_VALUE and (
1515+
enable_secure_boot is not None or enable_vtpm is not None):
15141516
security_profile['uefiSettings'] = {
15151517
'secureBootEnabled': enable_secure_boot,
15161518
'vTpmEnabled': enable_vtpm

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,7 @@ def update_vm(cmd, resource_group_name, vm_name, os_disk=None, disk_caching=None
15971597
vm.storage_profile.os_disk.managed_disk.id = disk_id
15981598
vm.storage_profile.os_disk.name = disk_name
15991599

1600+
from ._constants import COMPATIBLE_SECURITY_TYPE_VALUE
16001601
if security_type == "TrustedLaunch":
16011602
from azure.cli.core.azclierror import InvalidArgumentValueError
16021603
if vm.security_profile is not None and vm.security_profile.security_type == "ConfidentialVM":
@@ -1615,6 +1616,11 @@ def update_vm(cmd, resource_group_name, vm_name, os_disk=None, disk_caching=None
16151616
if vm.security_profile is None:
16161617
vm.security_profile = SecurityProfile()
16171618
vm.security_profile.security_type = security_type
1619+
elif security_type == COMPATIBLE_SECURITY_TYPE_VALUE:
1620+
if vm.security_profile is None:
1621+
vm.security_profile = SecurityProfile()
1622+
vm.security_profile.security_type = security_type
1623+
vm.security_profile.uefi_settings = None
16181624

16191625
if write_accelerator is not None:
16201626
update_write_accelerator_settings(vm.storage_profile, write_accelerator)
@@ -1683,7 +1689,7 @@ def update_vm(cmd, resource_group_name, vm_name, os_disk=None, disk_caching=None
16831689
if proximity_placement_group is not None:
16841690
vm.proximity_placement_group = {'id': proximity_placement_group}
16851691

1686-
if enable_secure_boot is not None or enable_vtpm is not None:
1692+
if security_type != COMPATIBLE_SECURITY_TYPE_VALUE and (enable_secure_boot is not None or enable_vtpm is not None):
16871693
if vm.security_profile is None:
16881694
vm.security_profile = SecurityProfile()
16891695

0 commit comments

Comments
 (0)