You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/loops.md
+7-38Lines changed: 7 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ ms.date: 10/19/2021
7
7
8
8
# Iterative loops in Bicep
9
9
10
-
This article shows you how to use the `for` syntax to iterate over items in a collection. You can use loops to define multiple copies of a resource, property, variable, module, or output. Use loops to avoid repeating syntax in your Bicep file and to dynamically set the number of copies to create during deployment.
10
+
This article shows you how to use the `for` syntax to iterate over items in a collection. You can use loops to define multiple copies of a resource, module, variable, property, or output. Use loops to avoid repeating syntax in your Bicep file and to dynamically set the number of copies to create during deployment.
11
11
12
12
### Microsoft Learn
13
13
@@ -17,7 +17,7 @@ To learn more about loops, and for hands-on guidance, see [Build flexible Bicep
17
17
18
18
Loops can be declared by:
19
19
20
-
- Using an **integer index**. This option works when your scenario is: "I want to create this many instances." The [range function](bicep-functions-array.md#range) creates an array of integers from the start index and containing the number of specified elements. Within the loop, you can use the integer index to modify values. For more information, see [Integer index](#integer-index).
20
+
- Using an **integer index**. This option works when your scenario is: "I want to create this many instances." The [range function](bicep-functions-array.md#range) creates an array of integers that begins at the start index and contains the number of specified elements. Within the loop, you can use the integer index to modify values. For more information, see [Integer index](#integer-index).
21
21
22
22
```bicep
23
23
[for <index> in range(<startIndex>, <numberOfElements>): {
@@ -59,15 +59,15 @@ Loops can be declared by:
59
59
60
60
## Loop limits
61
61
62
-
Bicep loop has these limitations:
62
+
Using loops in Bicep has these limitations:
63
63
64
64
- Loop iterations can't be a negative number or exceed 800 iterations.
65
65
- Can't loop a resource with nested child resources. Change the child resources to top-level resources. See [Iteration for a child resource](#iteration-for-a-child-resource).
66
66
- Can't loop on multiple levels of properties.
67
67
68
68
## Integer index
69
69
70
-
For a simple example of using an index, create a **variable**for an array of strings.
70
+
For a simple example of using an index, create a **variable**that contains an array of strings.
71
71
72
72
```bicep
73
73
param itemCount int = 5
@@ -154,38 +154,7 @@ resource storageAcct 'Microsoft.Storage/storageAccounts@2021-02-01' = [for name
154
154
155
155
The next example iterates over an array to define a property. It creates two subnets within a virtual network.
When you want to iterate over elements in a dictionary object, use the [items function](bicep-functions-array.md#items) to convert the object to an array. Use the `value` property to get properties on the objects.
226
+
To iterate over elements in a dictionary object, use the [items function](bicep-functions-array.md#items), which converts the object to an array. Use the `value` property to get properties on the objects.
For **resources and modules**, you can add an `if` expression with the loop syntax to conditionally deploy the collection.
280
249
281
-
The following example shows a nested loop combined with a filtered resource loop. Filters must be expressions that evaluate to a boolean value. In this example, a single condition is applied to all instances of the module.
250
+
The following example shows a loop combined with a condition statement. In this example, a single condition is applied to all instances of the module.
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/outputs.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ var user = {
39
39
output stringOutput string = user['user-name']
40
40
```
41
41
42
-
To return one of two values depending a condition in the deployment, use the the `?` operator. For more information, see [Conditional output](#conditional-output).
42
+
When the value to return depends on a condition in the deployment, use the the `?` operator. For more information, see [Conditional output](#conditional-output).
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/resource-declaration.md
+18-24Lines changed: 18 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,56 +13,52 @@ This article describes the syntax you use to add a resource to your Bicep file.
13
13
14
14
## Declaration
15
15
16
-
Add a resource declaration by using the `resource` keyword. The values you provide in the declaration are described in more details in this article.
16
+
Add a resource declaration by using the `resource` keyword. You set a symbolic name for the resource. The symbolic name isn't the same as the resource name. You use the symbolic name to reference the resource in other parts of your Bicep file.
Symbolic names are case-sensitive. They may contain letters, numbers, and _; but can't start with a number.
33
+
34
+
For the available resource types and version, see [Bicep resource reference](/azure/templates/). Bicep doesn't support `apiProfile`, which is available in [Azure Resource Manager templates (ARM templates) JSON](../templates/syntax.md).
35
+
24
36
To conditionally deploy a resource, use the `if` syntax. For more information, see [Conditional deployment in Bicep](conditional-resource-deployment.md).
25
37
26
38
```bicep
27
-
resource <symbolic-name> '<resource-type>@<api-version>' = if (condition) {
39
+
resource <symbolic-name> '<full-type-name>@<api-version>' = if (condition) {
28
40
<resource-properties>
29
41
}
30
42
```
31
43
32
44
To deploy more than one instance of a resource, use the `for` syntax. For more information, see [Iterative loops in Bicep](loops.md).
33
45
34
46
```bicep
35
-
resource <symbolic-name> '<resource-type>@<api-version>' = [for <item> in <collection>: {
47
+
resource <symbolic-name> '<full-type-name>@<api-version>' = [for <item> in <collection>: {
36
48
<properties-to-repeat>
37
49
}]
38
50
```
39
51
40
52
You can also use the `for` syntax on the resource properties to create an array.
<array-property>: [for <item> in <collection>: <value-to-repeat>]
46
58
}
47
59
}
48
60
```
49
61
50
-
## Resource type and version
51
-
52
-
When adding a resource to your Bicep file, start by setting the resource type and API version. These values determine the other properties that are available for the resource.
53
-
54
-
The following example shows how to set the resource type and API version for a storage account. The example doesn't show the full resource declaration.
You set a symbolic name for the resource. In the preceding example, the symbolic name is `stg`. The symbolic name isn't the same as the resource name. You use the symbolic name to reference the resource in other parts of your Bicep file. Symbolic names are case-sensitive. They may contain letters, numbers, and _; but can't start with a number.
63
-
64
-
Bicep doesn't support `apiProfile`, which is available in [Azure Resource Manager templates (ARM templates) JSON](../templates/syntax.md).
65
-
66
62
## Resource name
67
63
68
64
Each resource has a name. When setting the resource name, pay attention to the [rules and restrictions for resource names](../management/resource-name-rules.md).
@@ -173,7 +169,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2020-06-01' = {
173
169
174
170
The preceding properties are generic to most resource types. After setting those values, you need to set the properties that are specific to the resource type you're deploying.
175
171
176
-
Use intellisense or [template reference](/azure/templates/) to determine which properties are available and which ones are required. The following example sets the remaining properties for a storage account.
172
+
Use intellisense or [Bicep resource reference](/azure/templates/) to determine which properties are available and which ones are required. The following example sets the remaining properties for a storage account.
To assign an array to a property, use the `for` syntax.
194
-
195
189
## Dependencies
196
190
197
191
When deploying resources, you may need to make sure some resources exist before other resources. For example, you need a logical SQL server before deploying a database. You establish this relationship by marking one resource as dependent on the other resource. Order of resource deployment can be influenced in two ways: [implicit dependency](#implicit-dependency) and [explicit dependency](#explicit-dependency)
0 commit comments