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/bicep-import.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Imports in Bicep
3
3
description: This article describes how to import shared functionality and namespaces in Bicep.
4
4
ms.topic: conceptual
5
5
ms.custom: devx-track-bicep
6
-
ms.date: 12/06/2024
6
+
ms.date: 05/16/2025
7
7
---
8
8
9
9
# Imports in Bicep
@@ -47,6 +47,8 @@ Only statements that were [exported](#export-variables-types-and-functions) in t
47
47
48
48
You can use functionality that was imported from another file without restrictions. For example, you can use imported variables anywhere that a variable declared in-file would normally be valid.
49
49
50
+
Starting with [Bicep CLI version 0.31.X](https://github.com/Azure/bicep/releases/tag/v0.31.34), variables imported from other Bicep files are accessible within your user-defined functions, just like variables defined locally. For more information, see [User-defined functions](./user-defined-functions.md#define-functions).
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/bicep/user-defined-functions.md
+47-6Lines changed: 47 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,20 +3,19 @@ title: User-defined functions in Bicep
3
3
description: Describes how to define and use user-defined functions in Bicep.
4
4
ms.topic: conceptual
5
5
ms.custom: devx-track-bicep
6
-
ms.date: 04/28/2025
6
+
ms.date: 05/16/2025
7
7
---
8
8
9
9
# User-defined functions in Bicep
10
10
11
11
Within your Bicep file, you can create your own functions. These functions are available for use in your Bicep files. User-defined functions are separate from the [standard Bicep functions](./bicep-functions.md) that are automatically available within your Bicep files. Create your own functions when you have complicated expressions that are used repeatedly in your Bicep files. Using user-defined functions automatically enables [language version 2.0](../templates/syntax.md#languageversion-20) code generation.
12
12
13
-
[Bicep CLI version 0.26.X or higher](./install.md) is required to use this feature.
13
+
[Bicep CLI version 0.26.X or higher](https://github.com/Azure/bicep/releases/tag/v0.26.54) is required to use this feature.
14
14
15
15
## Limitations
16
16
17
17
There are some restrictions when defining a user function:
18
18
19
-
* The function can't access variables.
20
19
* The function can only use parameters that are defined in the function.
21
20
* The function can't use the [reference](bicep-functions-resource.md#reference) function or any of the [list](bicep-functions-resource.md#list) functions.
22
21
* Parameters for the function can't have default values.
@@ -30,8 +29,6 @@ Use the `func` statement to define user-defined functions.
The following examples show how to define and use user-defined functions:
36
33
37
34
```bicep
@@ -71,7 +68,7 @@ The outputs from the preceding examples are:
71
68
| nameArray | Array |["John"]|
72
69
| addNameArray | Array |["Mary","Bob","John"]|
73
70
74
-
With [Bicep CLI version 0.23.X or higher](./install.md), you have the flexibility to invoke another user-defined function within a user-defined function. In the preceding example, with the function definition of `sayHelloString`, you can redefine the `sayHelloObject` function as:
71
+
You have the flexibility to invoke another user-defined function within a user-defined function. In the preceding example, with the function definition of `sayHelloString`, you can redefine the `sayHelloObject` function as:
75
72
76
73
```bicep
77
74
func sayHelloObject(name string) object => {
@@ -102,6 +99,50 @@ The output from the preceding example is:
102
99
| ---- | ---- | ----- |
103
100
| elements | positiveInt | 3 |
104
101
102
+
As of [Bicep CLI version 0.30.X](https://github.com/Azure/bicep/releases/tag/v0.30.3), user-defined functions can access variables defined in the same Bicep file. The following example demonstrates how a user-defined function can reference a variable:
Starting with [Bicep CLI version 0.31.X](https://github.com/Azure/bicep/releases/tag/v0.31.34), variables imported from other Bicep files are accessible within your user-defined functions, just like variables defined locally.
119
+
120
+
Suppose you have a Bicep file named `shared.bicep` that exports a variable:
121
+
122
+
```bicep
123
+
// shared.bicep
124
+
@export()
125
+
var sharedPrefix = 'Contoso'
126
+
```
127
+
128
+
You can import this variable into your main Bicep file and use it inside a user-defined function:
For more information on importing variables, see [Export variables, types, and functions](./bicep-import.md#export-variables-types-and-functions).
145
+
105
146
## Use decorators
106
147
107
148
Decorators are written in the format `@expression` and are placed above function declarations. The following table shows the available decorators for functions.
0 commit comments