Microsoft Azure Resource Deploymentscripts Management Client Library for Python
This is the Microsoft Azure Resource Deploymentscripts Management Client Library for Python. It provides capabilities to manage deployment scripts within Azure Resource Manager (ARM) templates, allowing for custom steps like adding users, performing data plane operations, or creating self-signed certificates during deployments. The current version is 1.0.0b1, indicating a beta release. Azure SDK for Python packages, including beta releases, are published to PyPI regularly, reflecting active development.
Warnings
- gotcha This package is currently in a beta state (version 1.0.0b1). This means the API surface might change in future releases, potentially introducing breaking changes before a stable 1.0.0 release.
- gotcha Deployment scripts create supporting resources (a storage account and a container instance) for execution and troubleshooting. While these are usually cleaned up automatically, charges may be incurred if they are not removed successfully after the script finishes.
- gotcha For Azure Resource Manager (ARM) template deployment scripts, an identity is crucial. For API version 2019-10-01-preview, a managed identity is *required*. For API version 2020-10-01 or later, it is optional unless the script performs Azure-specific actions requiring authentication. Currently, only user-assigned managed identities are supported.
- gotcha When embedding multi-line scripts directly into an ARM template using the `scriptContent` property, the Azure portal and Azure DevOps pipelines may fail to parse them.
- breaking Other `azure-mgmt-resource-*` packages have moved to only target the latest API-Version available, removing older API versions. While not explicitly stated for `azure-mgmt-resource-deploymentscripts`, this is a common breaking change pattern across the Azure SDK for Python management libraries that could affect this package in the future.
Install
-
pip install azure-mgmt-resource-deploymentscripts -
pip install azure-identity
Imports
- DeploymentScriptsClient
from azure.mgmt.resource.deploymentscripts import DeploymentScriptsClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource.deploymentscripts import DeploymentScriptsClient
# Set environment variables for authentication and subscription ID:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# AZURE_SUBSCRIPTION_ID
# For local development, `DefaultAzureCredential` can often pick up credentials from `az login`.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")
if subscription_id == "YOUR_SUBSCRIPTION_ID":
print("WARNING: Please set the AZURE_SUBSCRIPTION_ID environment variable for a functional example.")
try:
credential = DefaultAzureCredential()
client = DeploymentScriptsClient(credential=credential, subscription_id=subscription_id)
print(f"DeploymentScriptsClient initialized successfully for subscription: {subscription_id}")
# Example: List deployment scripts (uncomment to run)
# print("Listing deployment scripts...")
# for script in client.deployment_scripts.list_by_subscription():
# print(f"- Script Name: {script.name}, Resource Group: {script.id.split('/')[4]}")
# To create, update, or delete deployment scripts, refer to the official Azure SDK samples
# for detailed usage of `client.deployment_scripts.begin_create_or_update` or other operations.
except Exception as e:
print(f"An error occurred during client initialization or operation: {e}")
print("Please ensure you are authenticated to Azure (e.g., `az login`) and AZURE_SUBSCRIPTION_ID is set.")