{"id":1940,"library":"azure-mgmt-sqlvirtualmachine","title":"Azure SQL Virtual Machine Management Client Library","description":"The `azure-mgmt-sqlvirtualmachine` library provides a client for managing Azure SQL Virtual Machines, allowing you to create, update, delete, and list SQL VMs and their associated resources (like SQL VM groups and availability groups). It is currently at version `0.5.0` (as of late 2019) and follows the typical Azure SDK release cadence for management plane libraries, though updates for this specific library have been infrequent.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/sqlvirtualmachine/azure-mgmt-sqlvirtualmachine","tags":["azure","cloud","sql","virtual machine","management","arm","iaas"],"install":[{"cmd":"pip install azure-mgmt-sqlvirtualmachine azure-identity","lang":"bash","label":"Install with Azure Identity"}],"dependencies":[{"reason":"Required for authentication with Azure services.","package":"azure-identity","optional":false}],"imports":[{"note":"The main client for interacting with SQL Virtual Machine resources.","symbol":"SqlVirtualMachineManagementClient","correct":"from azure.mgmt.sqlvirtualmachine import SqlVirtualMachineManagementClient"},{"note":"Model classes for resources and parameters are typically found in the `.models` submodule.","wrong":"from azure.mgmt.sqlvirtualmachine import SqlVirtualMachine","symbol":"SqlVirtualMachine","correct":"from azure.mgmt.sqlvirtualmachine.models import SqlVirtualMachine"},{"note":"Recommended credential provider for authenticating with Azure.","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.sqlvirtualmachine import SqlVirtualMachineManagementClient\n\n# Retrieve subscription ID from environment variable\n# You can get your subscription ID using Azure CLI: az account show --query id -o tsv\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\n\nif not subscription_id or subscription_id == \"YOUR_SUBSCRIPTION_ID\":\n    raise ValueError(\"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID' in the code.\")\n\n# Authenticate with Azure using DefaultAzureCredential\n# This will try various authentication methods (environment variables, managed identity, CLI, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a SQL Virtual Machine Management Client\nclient = SqlVirtualMachineManagementClient(credential, subscription_id)\n\nprint(f\"Listing SQL Virtual Machines in subscription: {subscription_id}...\")\ntry:\n    # Iterate through all SQL Virtual Machines in the subscription\n    sql_vms = client.sql_virtual_machines.list()\n    \n    found_vms = False\n    for vm in sql_vms:\n        found_vms = True\n        print(f\"  - Name: {vm.name}\")\n        print(f\"    Resource Group: {vm.id.split('/resourceGroups/')[1].split('/')[0]}\")\n        print(f\"    Location: {vm.location}\")\n        print(f\"    Provisioning State: {vm.provisioning_state}\")\n        if vm.sql_virtual_machine_group_id:\n            print(f\"    SQL VM Group ID: {vm.sql_virtual_machine_group_id}\")\n        print(\"-\" * 20)\n\n    if not found_vms:\n        print(\"No SQL Virtual Machines found in this subscription.\")\n    else:\n        print(\"\\nSuccessfully listed SQL Virtual Machines.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure AZURE_SUBSCRIPTION_ID is set and your credential has 'Reader' permissions (at least) on the subscription.\")\n","lang":"python","description":"This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list all SQL Virtual Machines within a specified subscription. Ensure the `AZURE_SUBSCRIPTION_ID` environment variable is set and your Azure principal has sufficient permissions (e.g., Reader role) to view resources."},"warnings":[{"fix":"Review the official Azure documentation for SQL Virtual Machines to understand current capabilities and consider if a newer API version or alternative tools (e.g., Azure CLI, REST API) are more appropriate for advanced or recently released features.","message":"The `azure-mgmt-sqlvirtualmachine` library is currently at version `0.5.0`, last updated in October 2019. While still functional, this indicates it uses an older API version and might lack support for newer features or follow an older SDK design pattern compared to more recently updated Azure SDK libraries. Users should verify its capabilities meet their current requirements.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Ensure `azure-identity` is installed and that your environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are set, or you are logged in via Azure CLI (`az login`). Verify the principal has the necessary RBAC permissions (e.g., 'Contributor' or specific resource roles) on the subscription or resource group.","message":"Authentication is a common hurdle. All Azure management libraries require proper authentication. Using `DefaultAzureCredential` from `azure-identity` is the recommended and most flexible approach, but it relies on correctly configured environment variables, Azure CLI login, or managed identity.","severity":"gotcha","affected_versions":"all"},{"fix":"Thoroughly review the Azure portal or CLI to confirm all dependent resources are present and correctly configured. Check resource names, IDs, locations, and network settings for accuracy before attempting to deploy or modify SQL Virtual Machines.","message":"When creating or updating resources, ensure that all dependent resources (e.g., Resource Group, Virtual Network, Storage Account) exist and are correctly specified. Misconfigured or missing prerequisites are frequent sources of `ResourceNotFound` or `BadRequest` errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}