Back to snippets

azure_private_dns_zone_creation_with_mgmt_sdk.py

python

This quickstart demonstrates how to authenticate and create a Priv

15d ago31 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azure_private_dns_zone_creation_with_mgmt_sdk.py
1import os
2from azure.identity import DefaultAzureCredential
3from azure.mgmt.privatedns import PrivateDnsManagementClient
4
5def main():
6    # Authentication using DefaultAzureCredential
7    # Ensure AZURE_SUBSCRIPTION_ID is set in your environment variables
8    subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "your-subscription-id")
9    resource_group_name = "myResourceGroup"
10    private_zone_name = "example.com"
11
12    # Initialize the Private DNS Management Client
13    client = PrivateDnsManagementClient(
14        credential=DefaultAzureCredential(),
15        subscription_id=subscription_id
16    )
17
18    # Create a Private DNS Zone
19    print(f"Creating Private DNS zone: {private_zone_name}...")
20    poller = client.private_zones.begin_create_or_update(
21        resource_group_name=resource_group_name,
22        private_zone_name=private_zone_name,
23        parameters={
24            "location": "global"
25        }
26    )
27    result = poller.result()
28    print(f"Created Private DNS zone: {result.name}")
29
30if __name__ == "__main__":
31    main()
azure_private_dns_zone_creation_with_mgmt_sdk.py - Raysurfer Public Snippets