Recap, what we have learned
In this training we have learned how to deploy a single resource or a complete virtual machine using Bicep.
In a bicep file:
- Parameters are used to define the values that are used in the deployment.
- The re-use of templates is a key factor in the deployment of resources.
- Modules are used to define a set of resources that are used together.
Deployment of Azure resources through Azure CLI.
Explain the following bicep terms
You've seen some bicep code in the previous guides.
In the below section will explain the terms used in the bicep code.
Allowed
@allowed([
'CapacityReservation'
'Free'
'LACluster'
'PerGB2018'
'PerNode'
'Premium'
'Standalone'
'Standard'
])
param skuName string = 'PerGB2018'
This is a parameter that is used to define the SKU name, the input must be a string and the allowed values are defined in the @allowed
attribute.
No other values are allowed, the template will fail if another value is used.
Variables
var varEnableLogAccessUsingOnlyResourcePermissions = true
This is a variable that is used to define the value of varEnableLogAccessUsingOnlyResourcePermissions
.
We use this to simplify the code and to make it more readable, all settings are defined on the top of the script.
A change to the variable will result in changed throughout the script, this wil save you time and effort.
Variables can also be used the set the name of a resources according to your best practices:
var postNumberLength = 3
var networkInterfaceName = 'nic-${vmName}-${padLeft(1, postNumberLength, '0')}'
var varOsDiskName = 'osdisk-${vmName}'
This will create a network interface name and os disk name according to the name of the VM.
For example if the vm name is myvm
the network interface name will be nic-myvm-001
and the os disk name will be osdisk-myvm
.
DependsOn
dependsOn: [
moduleResourceGroup
]
This deploys the resource after the moduleResourceGroup
is deployed.
For creating a VM the resource group and the network card must be created first, so the VM can be deployed in the resource group and the network card attached.
Empty and if statement
(!empty(privateIPAddress) ? 'Static' : 'Dynamic')
This is a statement that checks if the privateIPAddress
is not empty (!).
The ! will state the NOT of the empty statement.
If the privateIPAddress
is not empty the value Static
is used, if the privateIPAddress
is empty the value Dynamic
is used.
Operators
All bicep operators can be found here.
Version overview
This document has the following versions:
Version | Date | Overview of changes |
---|---|---|
1.0 | 2024-03-14 | Initial version. |