Best way to include an external definition into existing bicep file #5477
-
We have an open-source project where we want to use bicep to deploy a VM scale set. However different users of the project will want different VM Extensions deployed. These would be the extensions defined under virtualMachineProfile -> extensionProfile -> extensions. Since there is no #include functionality, what's the suggestion on the best way to solve this kind of problem? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I have been using this for my VMSS extensions for some time now. The disadvantage of using that approach is that the https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/VMSS-VM.bicep#L302 However, looking at the docs, it does look as if you can use the following, which is identical to Virtual Machines. I did some basic testing and it does appear to work fine. So based on that, I can offer you a solution, although for my answer I will model this on Virtual Machines, not VMSS, however now assuming they will function identically (I will do more research on this and likely move my VMSS template to use this method as well). So.... here is a Virtual Machine template, with a list of individual extensionshttps://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/VM-VM.bicep#L703 resource AppServerMonitoringAgent 'Microsoft.Compute/virtualMachines/extensions@2020-12-01' = if (VM.match && bool(VM.Extensions.MonitoringAgent)) {
name: 'MonitoringAgent'
parent: virtualMachine
location: resourceGroup().location here is a parameter file that gets passed into the template. "Extensions": {
"value": {
"MonitoringAgent": 1,
"IaaSDiagnostics": 1,
"DependencyAgent": 1,
"AzureMonitorAgent": 1,
"GuestHealthAgent": 1,
"VMInsights": 1,
... Based on the setting in the parameter file set to a 1 or 0, or if you prefer a true or a false, the extension condition will either include or exclude the extension. e.g. This is basically a feature flag model/pattern ... |
Beta Was this translation helpful? Give feedback.
-
Based on the title of the discussion, I figured that I would also offer an alternate perspective... for an answer. You can currently load external data from a file using loadtextcontext('file.json'), however there is currently no way to make that value for the file path a variable or a parameter, so it doesn't suit the needs of a user passing in alternate configurations. There is a request here to provide such functionality, however it is not currently supported. |
Beta Was this translation helpful? Give feedback.
I have been using this for my VMSS extensions for some time now.
https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachinescalesets?tabs=bicep#virtualmachinescalesetextension
The disadvantage of using that approach is that the
extensionprofile/extensions
does not supportconditions
.https://github.com/brwilkinson/AzureDeploymentFramework/blob/main/ADF/bicep/VMSS-VM.bicep#L302
However, looking at the docs, it does look as if you can use the following, which is identical to Virtual Machines. I did some basic testing and it does appear to work fine.
https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachinescalesets/extensions?tabs=bicep
So base…