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:

enter image description here

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.

You Might Also Like