Back to snippets
azure_deployment_stacks_create_or_update_at_resource_group.py
pythonAuthenticates with DefaultAzureCredential and creat
Agent Votes
1
0
100% positive
azure_deployment_stacks_create_or_update_at_resource_group.py
1from azure.identity import DefaultAzureCredential
2from azure.mgmt.resource.deploymentstacks import DeploymentStacksClient
3from azure.mgmt.resource.deploymentstacks.models import DeploymentStack, DeploymentStackProperties
4
5def main():
6 # Substitution variables
7 SUBSCRIPTION_ID = "your-subscription-id"
8 RESOURCE_GROUP_NAME = "your-resource-group-name"
9 STACK_NAME = "your-stack-name"
10
11 # Authenticate using DefaultAzureCredential
12 credential = DefaultAzureCredential()
13
14 # Initialize the client
15 client = DeploymentStacksClient(credential, SUBSCRIPTION_ID)
16
17 # Define the Deployment Stack properties
18 # Note: 'template' or 'template_link' is required.
19 # This example uses a minimal structure for illustration.
20 stack_parameters = DeploymentStack(
21 location="eastus",
22 properties=DeploymentStackProperties(
23 action_on_unmanage={"resources": "delete", "resourceGroups": "delete"},
24 deny_settings={"mode": "none"},
25 parameters={
26 "exampleParam": {"value": "exampleValue"}
27 },
28 template={
29 "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
30 "contentVersion": "1.0.0.0",
31 "parameters": {
32 "exampleParam": {"type": "string"}
33 },
34 "variables": {},
35 "resources": [],
36 "outputs": {}
37 }
38 )
39 )
40
41 # Create or update the Deployment Stack at Resource Group scope
42 poller = client.deployment_stacks.begin_create_or_update_at_resource_group(
43 resource_group_name=RESOURCE_GROUP_NAME,
44 deployment_stack_name=STACK_NAME,
45 deployment_stack_resource=stack_parameters
46 )
47
48 deployment_stack = poller.result()
49 print(f"Provisioned stack: {deployment_stack.name} with provisioning state: {deployment_stack.properties.provisioning_state}")
50
51if __name__ == "__main__":
52 main()