Skip to content

Commit b41b1b7

Browse files
Merge pull request #212537 from mumian/0923-function-samples-array
0923 function samples array
2 parents 964cbd5 + 723b3d3 commit b41b1b7

File tree

1 file changed

+108
-4
lines changed

1 file changed

+108
-4
lines changed

articles/azure-resource-manager/bicep/bicep-functions-array.md

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ description: Describes the functions to use in a Bicep file for working with arr
44
author: mumian
55
ms.topic: conceptual
66
ms.author: jgao
7-
ms.date: 04/12/2022
8-
7+
ms.date: 09/26/2022
98
---
9+
1010
# Array functions for Bicep
1111

1212
This article describes the Bicep functions for working with arrays. The lambda functions for working with arrays can be found [here](./bicep-functions-lambda.md).
@@ -195,6 +195,34 @@ The output from the preceding example with the default values is:
195195
| objectEmpty | Bool | True |
196196
| stringEmpty | Bool | True |
197197

198+
### Quickstart examples
199+
200+
The following example is extracted from a quickstart template, [SQL Server VM with performance optimized storage settings
201+
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.attestation/attestation-provider-create/main.bicep):
202+
203+
```bicep
204+
@description('Array containing DNS Servers')
205+
param dnsServers array = []
206+
207+
...
208+
209+
resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' = {
210+
name: vnetName
211+
location: location
212+
properties: {
213+
addressSpace: {
214+
addressPrefixes: vnetAddressSpace
215+
}
216+
dhcpOptions: empty(dnsServers) ? null : {
217+
dnsServers: dnsServers
218+
}
219+
...
220+
}
221+
}
222+
```
223+
224+
In the [conditional expression](./operators-logical.md#conditional-expression--), the empty function is used to check whether the **dnsServers** array is an empty array.
225+
198226
## first
199227

200228
`first(arg1)`
@@ -239,15 +267,15 @@ The output from the preceding example with the default values is:
239267

240268
`flatten(arrayToFlatten)`
241269

242-
Takes an array of arrays, and returns an array of sub-array elements, in the original order. Sub-arrays are only flattened once, not recursively.
270+
Takes an array of arrays, and returns an array of subarray elements, in the original order. Subarrays are only flattened once, not recursively.
243271

244272
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
245273

246274
### Parameters
247275

248276
| Parameter | Required | Type | Description |
249277
|:--- |:--- |:--- |:--- |
250-
| arrayToFlattern |Yes |array |The array of sub-arrays to flatten.|
278+
| arrayToFlattern |Yes |array |The array of subarrays to flatten.|
251279

252280
### Return value
253281

@@ -609,6 +637,39 @@ The output from the preceding example with the default values is:
609637
| stringLength | Int | 13 |
610638
| objectLength | Int | 4 |
611639

640+
### Quickstart examples
641+
642+
The following example is extracted from a quickstart template, [Deploy API Management in external VNet with public IP
643+
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.apimanagement/api-management-create-with-external-vnet-publicip):
644+
645+
```bicep
646+
@description('Numbers for availability zones, for example, 1,2,3.')
647+
param availabilityZones array = [
648+
'1'
649+
'2'
650+
]
651+
652+
resource exampleApim 'Microsoft.ApiManagement/service@2021-08-01' = {
653+
name: apiManagementName
654+
location: location
655+
sku: {
656+
name: sku
657+
capacity: skuCount
658+
}
659+
zones: ((length(availabilityZones) == 0) ? null : availabilityZones)
660+
...
661+
}
662+
```
663+
664+
In the [conditional expression](./operators-logical.md#conditional-expression--), the `length` function check the length of the **availabilityZones** array.
665+
666+
More examples can be found in these quickstart Bicep files:
667+
- [Backup Resource Manager VMs using Recovery Services vault
668+
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.recoveryservices/recovery-services-backup-vms/)
669+
- [Deploy API Management into Availability Zones](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.apimanagement/api-management-simple-zones)
670+
- [Create a Firewall and FirewallPolicy with Rules and Ipgroups](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/azurefirewall-create-with-firewallpolicy-apprule-netrule-ipgroups)
671+
- [Create a sandbox setup of Azure Firewall with Zones](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/azurefirewall-with-zones-sandbox)
672+
612673
## max
613674

614675
`max(arg1)`
@@ -729,6 +790,49 @@ The output from the preceding example with the default values is:
729790
| ---- | ---- | ----- |
730791
| rangeOutput | Array | [5, 6, 7] |
731792

793+
### Quickstart examples
794+
795+
The following example is extracted from a quickstart template, [Two VMs in VNET - Internal Load Balancer and LB rules
796+
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.compute/2-vms-internal-load-balancer):
797+
798+
```bicep
799+
...
800+
var numberOfInstances = 2
801+
802+
resource networkInterface 'Microsoft.Network/networkInterfaces@2021-05-01' = [for i in range(0, numberOfInstances): {
803+
name: '${networkInterfaceName}${i}'
804+
location: location
805+
properties: {
806+
...
807+
}
808+
}]
809+
810+
resource vm 'Microsoft.Compute/virtualMachines@2021-11-01' = [for i in range(0, numberOfInstances): {
811+
name: '${vmNamePrefix}${i}'
812+
location: location
813+
properties: {
814+
...
815+
}
816+
}]
817+
```
818+
819+
The Bicep file creates two networkInterface and two virtualMachine resources.
820+
821+
More examples can be found in these quickstart Bicep files:
822+
823+
- [Multi VM Template with Managed Disk](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.compute/vm-copy-managed-disks)
824+
- [Create a VM with multiple empty StandardSSD_LRS Data Disks](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.compute/vm-with-standardssd-disk)
825+
- [Create a Firewall and FirewallPolicy with Rules and Ipgroups](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/azurefirewall-create-with-firewallpolicy-apprule-netrule-ipgroups)
826+
- [Create an Azure Firewall with IpGroups](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/azurefirewall-create-with-ipgroups-and-linux-jumpbox)
827+
- [Create a sandbox setup of Azure Firewall with Zones](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/azurefirewall-with-zones-sandbox)
828+
- [Create an Azure Firewall with multiple IP public addresses](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/fw-docs-qs)
829+
- [Create a standard load-balancer](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/load-balancer-standard-create)
830+
- [Azure Traffic Manager VM example](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/traffic-manager-vm)
831+
- [Create A Security Automation for specific Alerts](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.security/securitycenter-create-automation-for-alertnamecontains)
832+
- [SQL Server VM with performance optimized storage settings](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.sqlvirtualmachine/sql-vm-new-storage)
833+
- [Create a storage account with multiple Blob containers](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.storage/storage-multi-blob-container)
834+
- [Create a storage account with multiple file shares](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.storage/storage-multi-file-share)
835+
732836
## skip
733837

734838
`skip(originalValue, numberToSkip)`

0 commit comments

Comments
 (0)