0
# DNS Zone Management
1
2
Comprehensive management of Azure DNS zones including creation, deletion, updating, and listing operations. Supports both public and private zones with virtual network associations for Azure-internal name resolution.
3
4
## Zone Operations
5
6
### Create or Update Zone
7
8
Creates a new DNS zone or updates an existing one with the specified configuration.
9
10
```python { .api }
11
def create_or_update(
12
self,
13
resource_group_name: str,
14
zone_name: str,
15
parameters: Union[Zone, IO[bytes]],
16
if_match: Optional[str] = None,
17
if_none_match: Optional[str] = None,
18
**kwargs: Any
19
) -> Zone:
20
"""
21
Create or update a DNS zone.
22
23
Args:
24
resource_group_name: Name of the resource group containing the zone
25
zone_name: Name of the DNS zone (e.g., "example.com")
26
parameters: Zone configuration parameters
27
if_match: ETag value for conditional updates (optimistic concurrency)
28
if_none_match: Set to "*" to prevent overwriting existing zones
29
30
Returns:
31
Zone: The created or updated DNS zone
32
33
Raises:
34
HttpResponseError: If the operation fails
35
"""
36
```
37
38
**Usage Example:**
39
40
```python
41
from azure.mgmt.dns.models import Zone
42
43
# Create a public DNS zone
44
zone_params = Zone(
45
location="global", # DNS zones are always global
46
zone_type="Public",
47
tags={"environment": "production", "team": "networking"}
48
)
49
50
zone = dns_client.zones.create_or_update(
51
resource_group_name="my-resource-group",
52
zone_name="example.com",
53
parameters=zone_params
54
)
55
56
print(f"Created zone: {zone.name}")
57
print(f"Name servers: {zone.name_servers}")
58
```
59
60
### Delete Zone
61
62
Permanently deletes a DNS zone and all its record sets. This is a long-running operation.
63
64
```python { .api }
65
def begin_delete(
66
self,
67
resource_group_name: str,
68
zone_name: str,
69
if_match: Optional[str] = None,
70
**kwargs: Any
71
) -> LROPoller[None]:
72
"""
73
Delete a DNS zone and all its record sets.
74
75
Args:
76
resource_group_name: Name of the resource group containing the zone
77
zone_name: Name of the DNS zone to delete
78
if_match: ETag value for conditional deletion
79
80
Returns:
81
LROPoller[None]: Long-running operation poller
82
83
Raises:
84
HttpResponseError: If the operation fails
85
"""
86
```
87
88
**Usage Example:**
89
90
```python
91
# Delete a DNS zone (this will also delete all record sets)
92
delete_operation = dns_client.zones.begin_delete(
93
resource_group_name="my-resource-group",
94
zone_name="example.com"
95
)
96
97
# Wait for deletion to complete
98
delete_operation.wait()
99
print("Zone deleted successfully")
100
```
101
102
### Get Zone
103
104
Retrieves the properties of a specific DNS zone.
105
106
```python { .api }
107
def get(
108
self,
109
resource_group_name: str,
110
zone_name: str,
111
**kwargs: Any
112
) -> Zone:
113
"""
114
Get properties of a DNS zone.
115
116
Args:
117
resource_group_name: Name of the resource group containing the zone
118
zone_name: Name of the DNS zone
119
120
Returns:
121
Zone: The DNS zone properties
122
123
Raises:
124
HttpResponseError: If the zone is not found
125
"""
126
```
127
128
**Usage Example:**
129
130
```python
131
zone = dns_client.zones.get(
132
resource_group_name="my-resource-group",
133
zone_name="example.com"
134
)
135
136
print(f"Zone: {zone.name}")
137
print(f"Record sets: {zone.number_of_record_sets}/{zone.max_number_of_record_sets}")
138
print(f"Name servers: {zone.name_servers}")
139
```
140
141
### Update Zone
142
143
Updates mutable properties of an existing DNS zone.
144
145
```python { .api }
146
def update(
147
self,
148
resource_group_name: str,
149
zone_name: str,
150
parameters: Union[ZoneUpdate, IO[bytes]],
151
if_match: Optional[str] = None,
152
**kwargs: Any
153
) -> Zone:
154
"""
155
Update properties of a DNS zone.
156
157
Args:
158
resource_group_name: Name of the resource group containing the zone
159
zone_name: Name of the DNS zone
160
parameters: Zone update parameters (typically just tags)
161
if_match: ETag value for conditional updates
162
163
Returns:
164
Zone: The updated DNS zone
165
166
Raises:
167
HttpResponseError: If the operation fails
168
"""
169
```
170
171
**Usage Example:**
172
173
```python
174
from azure.mgmt.dns.models import ZoneUpdate
175
176
# Update zone tags
177
zone_update = ZoneUpdate(
178
tags={"environment": "staging", "team": "networking", "cost-center": "IT"}
179
)
180
181
updated_zone = dns_client.zones.update(
182
resource_group_name="my-resource-group",
183
zone_name="example.com",
184
parameters=zone_update
185
)
186
187
print(f"Updated tags: {updated_zone.tags}")
188
```
189
190
### List Zones
191
192
List DNS zones within a resource group or subscription.
193
194
```python { .api }
195
def list_by_resource_group(
196
self,
197
resource_group_name: str,
198
top: Optional[int] = None,
199
**kwargs: Any
200
) -> ItemPaged[Zone]:
201
"""
202
List DNS zones in a resource group.
203
204
Args:
205
resource_group_name: Name of the resource group
206
top: Maximum number of zones to return
207
208
Returns:
209
ItemPaged[Zone]: Paginated list of DNS zones
210
"""
211
212
def list(
213
self,
214
top: Optional[int] = None,
215
**kwargs: Any
216
) -> ItemPaged[Zone]:
217
"""
218
List all DNS zones in the subscription.
219
220
Args:
221
top: Maximum number of zones to return
222
223
Returns:
224
ItemPaged[Zone]: Paginated list of DNS zones
225
"""
226
```
227
228
**Usage Examples:**
229
230
```python
231
# List zones in a specific resource group
232
zones = dns_client.zones.list_by_resource_group("my-resource-group")
233
for zone in zones:
234
print(f"Zone: {zone.name}, Records: {zone.number_of_record_sets}")
235
236
# List all zones in subscription
237
all_zones = dns_client.zones.list(top=50) # Limit to first 50 zones
238
for zone in all_zones:
239
print(f"Zone: {zone.name}, Resource Group: {zone.id.split('/')[4]}")
240
```
241
242
## Zone Data Model
243
244
### Zone Class
245
246
```python { .api }
247
class Zone:
248
"""
249
Represents a DNS zone resource in Azure.
250
251
A DNS zone contains DNS records and provides name resolution for a domain.
252
Zones can be public (internet-accessible) or private (Azure-internal only).
253
"""
254
255
# Read-only properties
256
id: str # Azure resource ID
257
name: str # Zone name (e.g., "example.com")
258
type: str # Resource type ("Microsoft.Network/dnszones")
259
etag: str # ETag for concurrency control
260
max_number_of_record_sets: int # Maximum allowed record sets
261
number_of_record_sets: int # Current number of record sets
262
name_servers: List[str] # Authoritative name servers
263
264
# Configurable properties
265
location: str # Always "global" for DNS zones
266
tags: Dict[str, str] # Resource tags for organization
267
zone_type: ZoneType # Public or Private
268
269
# Private zone properties (only for private zones)
270
registration_virtual_networks: List[SubResource] # VNets for auto-registration
271
resolution_virtual_networks: List[SubResource] # VNets for name resolution
272
```
273
274
### Zone Types
275
276
```python { .api }
277
class ZoneType(str, Enum):
278
"""DNS zone visibility and resolution scope."""
279
PUBLIC = "Public" # Internet-accessible zone
280
PRIVATE = "Private" # Azure-internal zone linked to VNets
281
```
282
283
## Private DNS Zones
284
285
Private zones provide DNS resolution within Azure virtual networks without exposing records to the internet.
286
287
**Usage Example:**
288
289
```python
290
from azure.mgmt.dns.models import Zone, ZoneType, SubResource
291
292
# Create a private DNS zone
293
private_zone = Zone(
294
location="global",
295
zone_type=ZoneType.PRIVATE,
296
resolution_virtual_networks=[
297
SubResource(id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/vnet1"),
298
SubResource(id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/vnet2")
299
],
300
tags={"purpose": "internal-services"}
301
)
302
303
zone = dns_client.zones.create_or_update(
304
resource_group_name="my-resource-group",
305
zone_name="internal.company.com",
306
parameters=private_zone
307
)
308
309
print(f"Created private zone: {zone.name}")
310
```
311
312
## Error Handling
313
314
DNS zone operations can fail for various reasons:
315
316
```python
317
from azure.core.exceptions import HttpResponseError
318
319
try:
320
zone = dns_client.zones.get("my-rg", "nonexistent.com")
321
except HttpResponseError as e:
322
if e.status_code == 404:
323
print("Zone not found")
324
elif e.status_code == 403:
325
print("Access denied - check permissions")
326
else:
327
print(f"Unexpected error: {e.status_code} - {e.message}")
328
```
329
330
Common error scenarios:
331
- **404 Not Found**: Zone doesn't exist
332
- **403 Forbidden**: Insufficient permissions
333
- **409 Conflict**: Zone name already exists (when using if_none_match)
334
- **412 Precondition Failed**: ETag mismatch (when using if_match)