Don Chambers
Don Chambers

Reputation: 4289

Import in a bicepparam file is not supported in the powershell module, but it is in the cli

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:

enter image description here

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.

enter image description here

Upvotes: 0

Views: 276

Answers (1)

Jahnavi
Jahnavi

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

enter image description here

PowerShell:

New-AzResourceGroupDeployment

New-AzResourceGroupDeployment -ResourceGroupName MyresourceGroup -Name 'xxxx' -TemplateParameterFile test.bicepparam

enter image description here

Upvotes: 0

Related Questions