Skip to content

Commit dc16ed6

Browse files
committed
add function samples
1 parent 48cf12f commit dc16ed6

File tree

1 file changed

+77
-59
lines changed

1 file changed

+77
-59
lines changed

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

Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ author: mumian
55
ms.topic: conceptual
66
ms.author: jgao
77
ms.date: 04/12/2022
8-
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).
@@ -54,36 +54,6 @@ The output from the preceding example with the default values is:
5454
| stringOutput | Array | ["efgh"] |
5555
| objectOutput | Array | [{"a": "b", "c": "d"}] |
5656

57-
### Quickstart examples
58-
59-
The following example is extracted from a quickstart template, [SQL Server VM with performance optimized storage settings
60-
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.sqlvirtualmachine/sql-vm-new-storage):
61-
62-
```bicep
63-
@description('Amount of data disks (1TB each) for SQL Data files')
64-
@minValue(1)
65-
@maxValue(8)
66-
param sqlDataDisksCount int = 1
67-
68-
@description('Amount of data disks (1TB each) for SQL Log files')
69-
@minValue(1)
70-
@maxValue(8)
71-
param sqlLogDisksCount int = 1
72-
73-
var dataDisksLuns = array(range(0, sqlDataDisksCount))
74-
var logDisksLuns = array(range(sqlDataDisksCount, sqlLogDisksCount))
75-
76-
output array1 array = dataDisksLuns
77-
output array2 array = logDisksLuns
78-
```
79-
80-
The output from the preceding example with the default values is:
81-
82-
| Name | Type | Value |
83-
| ---- | ---- | ----- |
84-
| array1 | Array | [0] |
85-
| array2 | Array | [1] |
86-
8757
## concat
8858

8959
`concat(arg1, arg2, arg3, ...)`
@@ -185,34 +155,6 @@ The output from the preceding example with the default values is:
185155
| arrayTrue | Bool | True |
186156
| arrayFalse | Bool | False |
187157

188-
### Quickstart examples
189-
190-
The following sample is extracted from a quickstart template, [Application Gateway with WAF and firewall policy](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/application-gateway-waf-firewall-policy):
191-
192-
```bicep
193-
backendHttpSettingsCollection: [for backendHttpSetting in backendHttpSettings: {
194-
name: backendHttpSetting.name
195-
properties: {
196-
port: backendHttpSetting.port
197-
protocol: backendHttpSetting.protocol
198-
cookieBasedAffinity: backendHttpSetting.cookieBasedAffinity
199-
affinityCookieName: contains(backendHttpSetting, 'affinityCookieName') ? backendHttpSetting.affinityCookieName : null
200-
requestTimeout: backendHttpSetting.requestTimeout
201-
connectionDraining: backendHttpSetting.connectionDraining
202-
probe: contains(backendHttpSetting, 'probeName') ? json('{"id": "${resourceId('Microsoft.Network/applicationGateways/probes', applicationGatewayName, backendHttpSetting.probeName)}"}') : null
203-
trustedRootCertificates: contains(backendHttpSetting, 'trustedRootCertificate') ? json('[{"id": "${resourceId('Microsoft.Network/applicationGateways/trustedRootCertificates', applicationGatewayName, backendHttpSetting.trustedRootCertificate)}"}]') : null
204-
hostName: contains(backendHttpSetting, 'hostName') ? backendHttpSetting.hostName : null
205-
pickHostNameFromBackendAddress: contains(backendHttpSetting, 'pickHostNameFromBackendAddress') ? backendHttpSetting.pickHostNameFromBackendAddress : false
206-
}
207-
}]
208-
```
209-
210-
More examples can be found in these quickstart Bicep files:
211-
212-
- [Route table with routes](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/route-table-create)
213-
- [Virtual Network with diagnostic logs](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.network/vnet-create-with-diagnostic-logs)
214-
- [App Service Quickstart - Linux App](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.web/app-service-docs-linux)
215-
216158
## empty
217159

218160
`empty(itemToTest)`
@@ -253,6 +195,34 @@ The output from the preceding example with the default values is:
253195
| objectEmpty | Bool | True |
254196
| stringEmpty | Bool | True |
255197

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+
**dnsServers** is assigned if the array is not empty.
225+
256226
## first
257227

258228
`first(arg1)`
@@ -667,6 +637,54 @@ The output from the preceding example with the default values is:
667637
| stringLength | Int | 13 |
668638
| objectLength | Int | 4 |
669639

640+
### Quickstart examples
641+
642+
The following example is extracted from a quickstart template, [SQL Server VM with performance optimized storage settings
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+
Assign **availabilityZones** to the **zones** property if **availabilityZones** contains 1 or more elements.
665+
666+
The following example is extracted from a quickstart template, [Backup Resource Manager VMs using Recovery Services vault
667+
](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.recoveryservices/recovery-services-backup-vms/):
668+
669+
```bicep
670+
param numberOfInstances int
671+
672+
resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-03-01' = [for i in range(0, length(range(0, numberOfInstances))): {
673+
name: '${virtualMachineName}${range(0, numberOfInstances)[i]}'
674+
location: location
675+
properties: {
676+
...
677+
}
678+
...
679+
}
680+
```
681+
682+
More examples can be found in these quickstart Bicep files:
683+
684+
- [Deploy API Management into Availability Zones](https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.apimanagement/api-management-simple-zones)
685+
- [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)
686+
- [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)
687+
670688
## max
671689

672690
`max(arg1)`

0 commit comments

Comments
 (0)