Skip to content


Sample rules

A few rules that use objects from this package:

from typing import Dict, List, Union

from import AzureEnvironmentContext
from import AzureVirtualMachine
from import AzureVirtualMachineScaleSet
from import AzureBaseRule
from cloudrail.knowledge.rules.base_rule import Issue
from cloudrail.knowledge.rules.rule_parameters.base_paramerter import ParameterType

class EnsureVmAndVmssUseManagedDisksRule(AzureBaseRule):

    def get_id(self) -> str:
        return 'non_car_virtual_machines_and_virtual_machine_scale_sets_only_use_managed_disks'

    def execute(self, env_context: AzureEnvironmentContext, parameters: Dict[ParameterType, any]) -> List[Issue]:
        issues: List[Issue] = []
        for virtual_machine in env_context.virtual_machines:
            if not virtual_machine.disk_settings.os_disk.is_managed_disk:
                self._append_issue(virtual_machine, issues)
        for vmss in env_context.virtual_machines_scale_sets:
            if not vmss.disk_settings.os_disk.is_managed_disk:
                self._append_issue(vmss, issues)
        return issues

    def should_run_rule(self, environment_context: AzureEnvironmentContext) -> bool:
        return bool(environment_context.virtual_machines or environment_context.virtual_machines_scale_sets)

    def _append_issue(vm_entity: Union[AzureVirtualMachine, AzureVirtualMachineScaleSet], issues_list: List[Issue]):
                f"The {vm_entity.get_type()} `{vm_entity.get_friendly_name()}` is using an unmanaged disk",
                vm_entity, vm_entity))

AzureVirtualMachineScaleSet (AzureResource)


Name Type Description
name str

The name of the Virtual machine scale set resource.

os_type OperatingSystemType

The VM's instances operating system. Either Windows or Linux.

disk_settings DiskSettings

The disk settings which will be used for the VM's instances.

network_interfaces_config List[AzureNetworkInterface]

The network interfaces configurations which will be used for the VM's instances.

upgrade_policy_mode Optional[UpgradePolicyMode]

Specifies the mode of an upgrade to virtual machines in the scale set.

sku Sku

The SKU configuration block for the scale set.

instances int

The number of Virtual Machines in the Scale Set.

source_image_reference SourceImageReference

The image used in the Virtual Machine OS.

disable_password_authentication Optional[bool]

If Password Authentication should be disabled on this Virtual Machine Scale Set (relavant for Linux OS).

extensions Optional[List[AzureVirtualMachineExtension]]

List of extension profiles to add to the scale set.

custom_invalidation(self) inherited

A list of manual reasons why this resource should be invalidated

exclude_from_invalidation(self) inherited

A list of attributes that should be excluded from the invalidation process

Sku dataclass


Name Type Description
name str

The SKU name

tier Optional[]

The tier of virtual machines in a scale set (Values: standard or basic)

capacity Optional[int]

The number of virtual machines in the scale set

SkuTier (str, Enum)

An enumeration.

UpgradePolicyMode (Enum)

An enumeration.