Create rbac policy for storage account and provide create container and read write permissions to dev and QA group
winget search Python.Python
winget install Python.Python.3
pip install azure-identity azure-mgmt-compute
sample code for azure sdk
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient
def stop_azure_vm():
# 1. Define configuration details
# It is best practice to pull your subscription ID from environment variables
SUBSCRIPTION_ID = os.getenv("AZURE_SUBSCRIPTION_ID", "your-subscription-id")
RESOURCE_GROUP = "your-resource-group-name"
VM_NAME = "your-virtual-machine-name"
print(f"Authenticating and initializing client...")
# 2. Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()
# 3. Initialize the Compute Management Client
compute_client = ComputeManagementClient(credential, SUBSCRIPTION_ID)
print(f"Sending stop request for VM: '{VM_NAME}' in Resource Group: '{RESOURCE_GROUP}'...")
# 4. Trigger the asynchronous power-off operation
async_vm_stop = compute_client.virtual_machines.begin_power_off(
resource_group_name=RESOURCE_GROUP,
virtual_machine_name=VM_NAME
)
# 5. Wait for the operation to successfully finish
async_vm_stop.wait()
print(f"Success: The VM '{VM_NAME}' has been successfully stopped and deallocated.")
if __name__ == "__main__":
stop_azure_vm()