Bicep - How to Initialize App Files of Powershell Azure Function (E. G. Requirements. Psd1)?

We are using Bicep to create an Azure Function App running a PowerShell function. This works well, except one detail.

Part of the function app definition are app files that we need to initialize upon creation, specifically requirements.psd1, where required modules are listed:

Can this be done in a Bicep file? If yes: how? If not: what is the recommended way of doing it?

(We are using Azure CLI with Bicep (az bicep), so a solution in that context would be nice.)

4

2 Answers

I'm for now resorting to deploying the requirements.psd1 file after the Bicep deployment. (Note: the Bicep deployment resets the file content on every deployment.)

Here's the Azure CLI command:

az webapp deploy --resource-group rg-contoso-test-westeurope --name func-contoso-test-westeurope --src-path "../../Azure/Functions/ContosoFunc/requirements.psd1" --clean false --target-path "/home/site/wwwroot/requirements.psd1" --type static

Late but I've actually found an solution for this:

resource function ' = {
  parent: azureFunctionApp
  name: 'BackupTable'
  properties: {
    ...
    files: {
      'run.ps1' : loadTextContent('../FunctionApp/DailyBackup/run.ps1')
      '../requirements.psd1' : loadTextContent('../FunctionApp/requirements.psd1')
    }
  }
}

Add the 'requirements.psd1' in the files of your function and it will work! For me at least.. i hope for others too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest