Function App App files -requirements.psd1

Viewed 715

When a function app is created (using the Powershell runtime), it comes with a requirements.psd1 files in the "App files" which has this content

This file enables modules to be automatically managed by the Functions service.
See https://aka.ms/functionsmanageddependency for additional information.
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
# 'Az' = '6.'
}

the line AZ=6. is commented, is there a way that this line can be uncommented at deployment time using ARM template or Azure Powershell?

1 Answers

I think you can't do that during the deployment, the workaround is to update the file after deployment via the Kudu API in poweshell.

Store the new requirements.psd1 with the path e.g. C:\Users\Administrator\Desktop\requirements.psd1 in local.

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
     'Az' = '6.*'
}

Then use the script below.

$appsvWebAppName = "<functionapp-name>"
$resourceGroupName = "<group-name>"

$resource = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName "$appsvWebAppName/publishingcredentials" -Action list -ApiVersion 2018-02-01 -Force

$username = $resource.Properties.publishingUserName
$password = $resource.Properties.publishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"


$apiUrl = "https://$appsvWebAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/requirements.psd1"
$filePath = "C:\Users\Administrator\Desktop\requirements.psd1"
$headers = @{
    'Authorization' = 'Basic ' + $base64AuthInfo
    'If-Match' = '*'
}
Invoke-RestMethod -Uri $apiUrl -Headers $headers -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"
Related