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: README.md
+232-35
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@
14
14
# Bicep Files & File Names
15
15
Bicep files use a `.bicep` file extension and are written using their own custom domain-specific language (DSL).
16
16
17
-
If you're accustomed to Terraform, you will see that Bicep works differently when it comes to deploying code. Terraform will combine every `.tf` file in the current directory and deploy all of them at the same time. Whereas Bicep will deploy one main `.bicep` file per deployment. It is suggested to name this file `main.bicep`
17
+
If you're accustomed to Terraform, you will see that Bicep works differently when it comes to deploying code. Terraform will combine every `.tf` file in the current directory and deploy them all at the same time. Whereas Bicep will deploy one main `.bicep` file per deployment. It is suggested to name this file `main.bicep`
18
18
19
19
If you are storing parameters values in a separate parameters JSON file, it is common practice to use the name of the Bicep file and just add the word "parameters" like shown below. If you are using the newer Bicep parameter format, then just use the name of the Bicep file with the extension of `.bicepparam`. Support for `.bicepparam` files requires Bicep v0.18.4 or later.
- You can use more than one decorator for each parameter definition
88
88
- It's good practice to specify the `minLength` and `maxLength` decorators for parameters that control resource naming. These limitations help avoid errors later during deployment
89
89
- For integers you can specify `minValue` and `maxValue` decorators, instead
90
-
- It's good practice to provide the `description` decorator for all of your parameters. Try to make them helpful
90
+
- It's good practice to specify the `description` decorator for all of your parameters. Try to make them helpful
91
91
- The `allowed` decorator can be used to provide allowed values in an array. If the value doesn't match, then the deployment fails
92
92
- Use this sparingly, as Azure makes changes frequently to things like SKUs and sizes, so you don't want to have an allowed list that is out of date
93
93
- The `metadata` decorator is an object that can contain properties of any name and type. Use this for info that you don't want to put into the `description` decorator
Instead of storing parameter values directly in your `.bicep` file, you can store the values externally in a `.bicepparam` or `.json` file. Then, you'd pass this parameter file, along with the `.bicep` file, to your deployment.
524
+
525
+
> [!NOTE]
526
+
> This guide is only going to cover the newer `.bicepparam` files. If you'd like to know more about the older `.json` parameter files, then please reference [the documentation](https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/parameter-files).
Each `.bicepparam` file is tied to a particular `.bicep` file. This relationship is defined by the `using` statement. There are multiple options for defining the `using` statement, see below for more.
545
+
- Support for ARM Templates, Bicep Registries, and Template Specs was added in Bicep v0.22.6
546
+
547
+
```bicep
548
+
// a regular bicep file or arm template
549
+
using 'path/to/file.bicep'
550
+
using 'path/to/file.json'
551
+
552
+
// a module from the public bicep registry
553
+
using 'br/public:path:tag'
554
+
555
+
// a module from a private bicep registry
556
+
using 'br:registryName.azurecr.io/bicep/path:tag'
557
+
using 'br/aliasName:path:tag'
558
+
559
+
// a template spec
560
+
using 'ts:subscriptionId/resourceGroupName/specName:tag'
561
+
using 'ts/aliasName:specName:tag'
562
+
563
+
// NOT tied to anything
564
+
using none
565
+
```
566
+
567
+
Starting with Bicep v0.21.1 you can define optional Variables in your `.bicepparam` files.
568
+
569
+
You can use expressions in the value of each parameter.
570
+
- Use the `readEnvironmentVariable` function to pull a value from an environment variable.
571
+
- Don't store sensitive values in your parameter files. Instead, use the `az.getSecret` function to pull the value from Key Vault.
572
+
- The `az.getSecret` function can only pull secrets from Key Vault.
573
+
- The `az.getSecret` function can only be used in a `param` value
574
+
- The `az.getSecret` function only supports params that have the `@secure()` decorator
575
+
- By default, it will pull the latest version of the secret, unless you specify the `secretVersion` parameter
576
+
519
577
# Conditions (If)
520
578
You can deploy a resource only if a certain condition is met, otherwise the resource will not be deployed
521
579
@@ -606,7 +664,7 @@ multi-line comment
606
664
*/
607
665
```
608
666
609
-
## Interpolation
667
+
## String Interpolation
610
668
- All strings in Bicep support interpolation
611
669
- To inject an expression surround it by `${` and `}`
612
670
@@ -630,19 +688,45 @@ The true or false values can be of any data type: string, integer, boolean, obje
630
688
631
689
Bicep has a large assortment of functions that can be used in your template. Check out the [officials docs](https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions) for more information about all of the available Functions and their instructions.
632
690
691
+
### User-defined Functions
692
+
- Support for User-defined Functions requires Bicep v0.26.54 or later
693
+
- Allows you to create and use your own custom functions within a Bicep file
694
+
- Great for when you have complicated expressions that are used repeatedly in your Bicep files
695
+
- They can be nested, you can call a User-defined Function from another User-defined function
696
+
- They support custom User-defined Data Types
697
+
- Some limitations:
698
+
- Can't access variables
699
+
- Can only use parameters that are defined in the function
700
+
- Parameters defined in the function can't have default values
701
+
- Can't use the `reference` or `list` functions
702
+
-[Read the docs](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/user-defined-functions) for more information on User-defined Functions
// first, define the functionName that you want to give to this user-defined function
709
+
// then, define any arguments that the function uses, specify a name and a data type for each argument
710
+
// then, define the data type of the function's return value
711
+
// finally, define what value the function will return by creating a custom expression that uses the arguments
712
+
```
713
+
633
714
### Lambda Expressions
634
-
- Lambda Expressions are supported starting with Bicep v0.10.61.
635
-
- Lambda Expressions can only be used as arguments on 5 specific functions: `filter`, `map`, `reduce`, `sort`, and `toObject`. See below for examples of each one
715
+
- Lambda Expressions can only be used as arguments on the following specific functions:
716
+
-`filter()`, `map()`, `reduce()`, `sort()` - Supported with Bicep v0.10.61 onward
717
+
-`toObject()` - Supported with Bicep v0.14.6 onward
718
+
-`groupBy()`, `mapValues()` - Supported with Bicep v0.27.1 onward
636
719
- The general format of a Lambda Expression is `lambdaVariable => lambdaExpression`.
637
720
-[Read the docs](https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions-lambda) for more information and examples for Lamba Expressions.
638
721
639
722
Example: `filter()`
640
723
641
724
```bicep
725
+
filter(inputArray, lambdaExpression)
642
726
// input: array
643
-
// lambaExpression: run a test against each element of the array
727
+
// lambaExpression: expression/test to run against each element of the array
728
+
// - Supports an optional index as of Bicep v0.27.1
644
729
// output: array (containing only elements that passed the test)
// This creates a dictionary object, where the key of each element is the 'name' and the value of each one is 'age'
769
927
// This example includes the optional 2nd lambaExpression, and we get a return value like this:
770
-
// {
771
-
// Reba: 24
772
-
// Garth: 10
773
-
// }
928
+
someOutput2 = {
929
+
Reba: 24
930
+
Garth: 10
931
+
}
774
932
```
775
933
934
+
### Import / Export
935
+
- First, you can specify the `@export()` decorator on any User-defined Type (`type`), User-defined Function (`func`), or Variable (`var`). This marks the item as being exportable.
936
+
- Then, you can use the `import` function, in a totally different Bicep file, to import that `type`, `func`, or `var` from the first Bicep file.
937
+
- Support for Compile-time Imports is generally available as of Bicep v0.25.3
938
+
939
+
Example `exports.bicep` file:
940
+
```bicep
941
+
@export()
942
+
type myUserDefinedType = {
943
+
something: string
944
+
anotherthing: int
945
+
}
946
+
947
+
@export()
948
+
func myUserDefinedFunction(name string) string => 'Hey there ${name}'
949
+
950
+
@export()
951
+
var myVariable = 'some constant value'
952
+
// can only use constant values, or references to other variables
953
+
// can not use references to resources, modules, or parameters
954
+
```
955
+
956
+
Example `main.bicep` file:
957
+
```bicep
958
+
// method 1, import the given items from exports.bicep
959
+
import {myUserDefinedType, myVariable} from 'exports.bicep'
960
+
961
+
// method 1, same as above, but define an optional alias that you can use
962
+
import {myVariable as newVariableAlias} from 'exports.bicep'
963
+
964
+
// method 2, import everything from exports.bicep into the symbolic name allImports
965
+
// then reference each item like so: allImports.myUserDefinedType, allImports.myUserDefinedFunction, allImports.myVariable
966
+
import * as allImports from 'exports.bicep'
967
+
```
968
+
969
+
Support for `.bicepparam` files
970
+
- As of Bicep v0.22.6, you can import Variables in your `.bicepparam` files
971
+
- As of Bicep v0.26.54, you can import User-defined Functions in your `.bicepparam` files
972
+
776
973
---
777
974
778
975
## Examples of getting info from ARM Resource Provider (WIP)
0 commit comments