Skip to content

Commit 968fae2

Browse files
feat: Introduce Zone-Redundancy interface for Bicep (#1870)
1 parent daf41f8 commit 968fae2

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

docs/content/specs-defs/specs/bicep/interfaces.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,32 @@ Which returns a JSON-formatted output like:
275275
This interface is a **SHOULD** instead of a **MUST** and therefore the AVM core team have not mandated a interface schema to use.
276276

277277
{{% /notice %}}
278+
279+
## Zonal & zone-redundant resources
280+
281+
Many Azure resources can be deployed into specific availability zones. Depending on whether a resource is 'zonal' (i.e., deploys a single instance into a single zone) or 'zone-redundant' (i.e., spreads multiple of its instances across the configured zones), implementing a different interface is required. Simply put, the zone of a zonal resource must be a required parameter (but give the user the option to 'opt-out'), while zone-redundant resources must span all available zones by default, but still give the user the option to 'opt-out'. Please note that the support for Availability Zones may differ from region to region.
282+
283+
{{< tabs title="" >}}
284+
{{% tab title="Variant 1: Zone-redundant resource (e.g., VirtualMachineScaleSet)" %}}
285+
286+
{{< highlight lineNos="false" type="bicep" wrap="true" title="Parameter & Resource Example" >}}
287+
{{% include file="/static/includes/interfaces/bicep/int.zone.schema1.bicep" %}}
288+
{{< /highlight >}}
289+
290+
{{< highlight lineNos="false" type="bicep" wrap="true" title="Input Example with Values" >}}
291+
{{% include file="/static/includes/interfaces/bicep/int.zone.input1.bicep" %}}
292+
{{< /highlight >}}
293+
294+
{{% /tab %}}
295+
{{% tab title="Variant 2: Zonal resource (e.g., Compute Disk)" %}}
296+
297+
{{< highlight lineNos="false" type="bicep" wrap="true" title="Parameter & Resource Example" >}}
298+
{{% include file="/static/includes/interfaces/bicep/int.zone.schema2.bicep" %}}
299+
{{< /highlight >}}
300+
301+
{{< highlight lineNos="false" type="bicep" wrap="true" title="Input Example with Values" >}}
302+
{{% include file="/static/includes/interfaces/bicep/int.zone.input2.bicep" %}}
303+
{{< /highlight >}}
304+
305+
{{% /tab %}}
306+
{{< /tabs >}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
availabilityZone: -1 // Deploy into no zone
2+
availabilityZone: 1 // Deploy into zone 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
availabilityZones: [] // Deploy into no zone
2+
availabilityZones: [1, 2] // Deploy into zone 1 & 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ============== //
2+
// Parameters //
3+
// ============== //
4+
5+
@description('Required. If set to 1, 2 or 3, the availability zone is hardcoded to that value. If set to -1, no zone is defined. Note that the availability zone numbers here are the logical availability zone in your Azure subscription. Different subscriptions might have a different mapping of the physical zone and logical zone. To understand more, please refer to [Physical and logical availability zones](https://learn.microsoft.com/en-us/azure/reliability/availability-zones-overview?tabs=azure-cli#physical-and-logical-availability-zones) and [Distribute VMs and disks across availability zones](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-high-availability#distribute-vms-and-disks-across-availability-zones).')
6+
@allowed([
7+
-1
8+
1
9+
2
10+
3
11+
])
12+
param availabilityZone int
13+
14+
// ============= //
15+
// Resources //
16+
// ============= //
17+
18+
resource >singularMainResourceType< '>providerNamespace</>resourceType<@>apiVersion<' = {
19+
name: '>exampleResource<'
20+
properties: {
21+
... // other properties
22+
zones: !empty(availabilityZone) ? array(string(availabilityZone)) : null
23+
}
24+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// ============== //
2+
// Parameters //
3+
// ============== //
4+
5+
@description('Optional. The list of Availability zones to use for the zone-redundant resources.')
6+
@allowed([
7+
1
8+
2
9+
3
10+
])
11+
param availabilityZones int[] = [1, 2, 3]
12+
13+
// ============= //
14+
// Resources //
15+
// ============= //
16+
17+
resource >singularMainResourceType< '>providerNamespace</>resourceType<@>apiVersion<' = {
18+
name: '>exampleResource<'
19+
properties: {
20+
... // other properties
21+
zones: map(availabilityZones ?? [], zone => '${zone}')
22+
}
23+
}

0 commit comments

Comments
 (0)