Reputation: 4289
I am using the import functionality in a bicep parameter file (bicepparam).
This works with the azure cli, but fails with the powershell module with the follow error:
Error BCP337: This declaration type is not valid for a Bicep Parameters file. Specify a "using" or "param" declaration.
I am using Bicep CLI version 0.28.1, and version 12.0.0 of the Az powershell module.
I enable user defined funcitons with this bicepconfig.json file:
{
"experimentalFeaturesEnabled": {
"compileTimeImports": true,
"userDefinedFunctions": true
}
}
I add an export function in a cfg.bicep file:
@export()
func testFunction(x string) string => x
I import this in a test.bicepparam file
using 'test.bicep'
import * as vars from 'cfg.bicep'
param theVal = vars.testFunction('A Test String')
And this is my bicep file (test.bicep):
param theVal string
output Value string = theVal
I use this azure cli command:
az deployment group create --name 'aaaaa' --resource-group MyResourceGroup --parameters $paramFile
This works, and I see the parameter named theVal has the correct string from the parameter file:
This fails when I use the powershell module with the same inputs. Here is the command:
New-AzResourceGroupDeployment -ResourceGroupName MyresourceGroup -Name 'aaaaa' -TemplateParameterFile $paramFile
I get the error at the beginning of this question: This declaration type is not valid for a Bicep Parameters file. Specify a "using" or "param" declaration.
UPDATE:
I've tried the solution Jahnavi and it's still not working. I get the same result.
Upvotes: 0
Views: 276
Reputation: 8018
Instead of trying it with $paramFile
, pass bicepparam
file directly with -TemplateParameterFile
parameter in the way
-TemplateParameterFile test.bicepparam
without a $
symbol.
$
in PowerShell or @
in CLI are not used when deploying a bicepparam
file using bicep. If you are using JSON
parameters file, then these will be needed for deploying and loading the contents of the file.
I have tried the same configuration as you did and was working for me with CLI & PowerShell as shown below.
test.bicepparam
:
using 'test.bicep'
import * as vars from 'cfg.bicep'
param theVal = vars.testFunction('A Test String')
CLI:
az deployment group create --name 'xxxx' --resource-group xxx --parameters test.bicepparam
PowerShell:
New-AzResourceGroupDeployment -ResourceGroupName MyresourceGroup -Name 'xxxx' -TemplateParameterFile test.bicepparam
Upvotes: 0