I want to pass in both a parameter file and inline parameters, for example:
New-AzDeployment -Name VmDeployment `
-TemplateFile C:\template\template.bicep`
-TemplateParameterFile C:\template\parameters.bicepparam`
-virtualMachineName VMName42
Bicep file:
param virtualMachineName string
param vnetName string
...
Bicepparam file:
using 'template.bicep'
param vnetName = "myVnet"
When I do this, I can't perform the deploy as the validation doesn't pass as the bicepparam file wants me to set all params available in template.bicep
file.
See below, with my real values:
A workaround is to do this:
using 'template.bicep'
param vnetName = "myVnet"
param virtualMachineName = "WILL_BE_CHANGED"
This validates and works, but looks really ugly. Any better solution?
I want to pass in both a parameter file and inline parameters, for example:
New-AzDeployment -Name VmDeployment `
-TemplateFile C:\template\template.bicep`
-TemplateParameterFile C:\template\parameters.bicepparam`
-virtualMachineName VMName42
Bicep file:
param virtualMachineName string
param vnetName string
...
Bicepparam file:
using 'template.bicep'
param vnetName = "myVnet"
When I do this, I can't perform the deploy as the validation doesn't pass as the bicepparam file wants me to set all params available in template.bicep
file.
See below, with my real values:
A workaround is to do this:
using 'template.bicep'
param vnetName = "myVnet"
param virtualMachineName = "WILL_BE_CHANGED"
This validates and works, but looks really ugly. Any better solution?
Share Improve this question edited Jan 20 at 7:51 Vinay B 2,5562 gold badges3 silver badges12 bronze badges Recognized by Microsoft Azure Collective asked Jan 18 at 0:40 MaxMax 68510 silver badges23 bronze badges 2- 1 i guess your approach is right github/Azure/bicep/issues/12805#issuecomment-1866552010 – DMabulage Commented Jan 18 at 1:33
- Thanks, seems so, should be documented better. – Max Commented Jan 18 at 13:34
1 Answer
Reset to default 0Passing both inline parameters and bicepparam file while using bicep configuration
I understand that the requirement of passing a bicep file and parameters.bicepparam file along with inline parameter which in general need to change or updated is possible but only issue seems to be you're not matching the configuration in both the files.
Since the VM name input should be provided as variable you need to declare the same in variable bicepparam file in order to match the configuration how ever since you need to define the input from the cli or PowerShell command.
In this case in order to achieve the requirement of using the inline command along with bicepparam file you need to define the VM name inside the bicepparam file with empty input and then you need define the input from the command.
configuration:
param vnetName string
param location string = resourceGroup().location
param vmSize string = 'Standard_D2s_v3'
param adminUsername string = 'azureuser'
@secure()
param adminPassword string
.
.
.
resource vm 'Microsoft.Compute/virtualMachines@2023-07-01' = {
name: virtualMachineName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: virtualMachineName
adminUsername: adminUsername
adminPassword: adminPassword
}
storageProfile: {
imageReference: {
publisher: 'MicrosoftWindowsServer'
offer: 'WindowsServer'
sku: '2022-datacenter'
version: 'latest'
}
osDisk: {
createOption: 'FromImage'
managedDisk: {
storageAccountType: 'StandardSSD_LRS'
}
}
}
networkProfile: {
networkInterfaces: [
{
id: nic.id
}
]
}
}
}
paramaters.bicepparam:
using 'main.bicep'
param vnetName = 'defaultVNet'
param virtualMachineName = ''
param adminPassword = 'yourpassword'
Here I passed the input to VM name as blank so that it can be picked from the inline command.
Deployment:
az deployment group create --name myDeployment --resource-group vinay-rg --template-file main.bicep --parameters parameters.bicepparam --parameters virtualMachineName=VMvk
Here we add the VM name to parambicep file to match the configuration however we pass the command through inline command input.
Refer:
https://learn.microsoft/en-us/azure/azure-resource-manager/bicep/parameter-files?tabs=Bicep#parameters-file