Azure Deployment Stacks Management

1.0.0 · active · verified Thu Apr 09

The `azure-mgmt-resource-deploymentstacks` library is the Microsoft Azure Resource Deployment Stacks Management Client Library for Python (version 1.0.0). It provides programmatic access to manage Azure Deployment Stacks, a native Azure resource type designed for managing collections of Azure resources as a single unit across different management scopes. This package is part of the broader Azure SDK for Python and supports Python 3.9+.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list all Deployment Stacks within a specified Azure subscription.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource.deploymentstacks import DeploymentStacksClient

# Set environment variables for authentication:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET for Service Principal/OAuth
# AZURE_SUBSCRIPTION_ID for the target subscription

subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")

if not subscription_id:
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

# Authenticate using DefaultAzureCredential, which attempts various methods
# (e.g., environment variables, managed identity, Azure CLI).
credential = DefaultAzureCredential()

# Create a Deployment Stacks client
client = DeploymentStacksClient(credential=credential, subscription_id=subscription_id)

# Example: List all deployment stacks in the current subscription
print(f"Listing deployment stacks for subscription: {subscription_id}")

try:
    for stack in client.deployment_stacks.list_at_subscription_scope():
        print(f"- Name: {stack.name}, Resource Group: {stack.resource_group}")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure your credentials have 'Microsoft.Resources/deploymentStacks/read' permission.")

print("\nQuickstart finished.")

view raw JSON →