Functions

Overview

The Functions builder is used to create Azure Functions accounts. It abstracts the App Host and Service Plan into the same component, and will also create and configure a linked App Insights resource. In addition, it will automatically create a backing storage account required by the functions runtime.

  • Web Site (Microsoft.Web/sites)
  • Web Host (Microsoft.Web/serverfarms)
  • Application Insights (Microsoft.Insights/components)
  • Storage Accounts (Microsoft.Storage/storageAccounts)

Builder Keywords

KeywordPurpose
nameSets the name of the functions instance.
service_plan_nameSets the name of the service plan hosting the function instance.
link_to_service_planInstructs Farmer to link this webapp to an existing service plan rather than creating a new one.
link_to_unmanaged_service_planInstructs Farmer to link this Functions instance to an existing service plan that is externally managed, rather than creating a new one.
link_to_storage_accountDo not create an automatic storage account; instead, link to a storage account that is created outside of this Functions instance but within this Farmer template.
link_to_unmanaged_storage_accountDo not create an automatic storage account; instead, link to an existing storage account that was created external to Farmer.
https_onlyDisables http for this functions app so that only HTTPS is used.
ftp_stateAllows to enable or disable FTP and FTPS.
app_insights_nameSets the name of the automatically-created app insights instance.
app_insights_offRemoves any automatic app insights creation, configuration and settings for this webapp.
link_to_app_insightsInstead of creating a new AI instance, configure this webapp to point to another AI instance that you are managing yourself.
link_to_unmanaged_app_insightsInstructs Farmer to link this functions instance to an existing app insights instance that is externally managed, rather than creating a new one.
use_runtimeSets the runtime of the Functions host.
use_extension_versionSets the extension version of the functions host.
operating_systemSets the operating system of the Functions host.
settingSets an app setting of the web app in the form “key” “value”.
secret_settingSets a “secret” app setting of the function. You must supply the “key”, whilst the value will be supplied as a secure parameter or an ARM expression.
settingsSets a list of app setting of the web app as tuples in the form of (“key”, “value”).
connection_stringCreates a connection string whose value is supplied as secret parameter, or as an ARM expression in the tupled form of (“key”, expr).
connection_stringsCreates a set of connection strings whose values will be supplied as secret parameters.
depends_onSets dependencies for the web app.
enable_corsEnables CORS support for the app. Either specify AllOrigins or a list of valid URIs.
enable_cors_credentialsAllows CORS requests with credentials.
add_identityAdds a managed identity to the the Function App.
system_identityActivates the system identity of the Function App.
always_onStops the app from sleeping if idle for a few minutes of inactivity.
worker_processSpecifies whether to set the app to 32 or 64 Bitness.
publish_asSpecifies whether to publish function as code or as a docker container.
add_slotAdds a deployment slot to the app
add_slotsAdds multiple deployment slots to the app
health_check_pathSets the path to your functions health check endpoint, which Azure load balancers will ping to determine which instances are healthy.
add_allowed_ip_restrictionAdds an ‘allow’ rule for an ip
add_denied_ip_restrictionAdds an ‘deny’ rule for an ip
link_to_vnetEnable the VNET integration feature in azure where all outbound traffic from the function with be sent via the specified subnet. Use this operator when the given VNET is in the same deployment
link_to_unmanaged_vnetEnable the VNET integration feature in azure where all outbound traffic from the function with be sent via the specified subnet. Use this operator when the given VNET is not in the same deployment
max_scale_out_limitMaximum number of workers that a site can scale out to. This setting only applies to the Consumption and Elastic Premium Plans

Post-deployment Builder Keywords

The Functions builder contains special commands that are executed after the ARM deployment is completed.

KeywordPurpose
zip_deploySupplying a folder or zip file will instruct Farmer to upload the contents directly to the Azure Functions once the ARM deployment is complete.
zip_deploy_slotSupplying a folder or zip file will instruct Farmer to upload the contents directly to the named slot of the Azure Functions once the ARM deployment is complete.

Key Vault integration

The Function builder comes with special integration into KeyVault. By activating KeyVault integration, the function builder can automatically link to, or even create, a full KeyVault instance. All Secret or ARM Expression-based Settings (e.g. a setting that links to the Key of a Storage Account) will automatically be redirected to KeyVault. The value will be stored in KeyVault and the system identity will be activated and provided into the KeyVault with GET permissions. Lastly, Function app settings will remain in place, using the Azure Functions built-in KeyVault redirection capabilities.

The following keywords exist on the function:

MemberPurpose
use_keyvaultTells the function app to create a brand new KeyVault for this Function’s secrets.
link_to_keyvaultTells the function to use an existing Farmer-managed KeyVault which you have defined elsewhere. All secret settings will automatically be mapped into KeyVault.
link_to_unmanaged_keyvaultTells the web app to use an existing non-Farmer managed KeyVault which you have defined elsewhere. All secret settings will automatically be mapped into KeyVault.

Configuration Members

MemberPurpose
PublishingPasswordGets the ARM expression path to the publishing password of this functions app.
StorageAccountKeyGets the ARM expression path to the storage account key of this functions app.
AppInsightsKeyGets the ARM expression path to the app insights key of this functions app, if it exists.
DefaultKeyGets the ARM expression path for the default key of this functions app.
MasterKeyGets the ARM expression path for the master key of this functions app.

Example

open Farmer
open Farmer.Builders

let myFunctions = functions {
    name "myWebApp"
    service_plan_name "myServicePlan"
    setting "myKey" "aValue"
    app_insights_off
}

Example of a Premium Functions app

let servicePlan = servicePlan {
    name "myServicePlan"
    sku WebApp.Sku.EP1 // Elastic Premium 1
    max_elastic_workers 25
}

let functionsApp = functions {
    name "myFunctionsApp"
    link_to_service_plan servicePlan
}

let deployment = arm {
    add_resources [ servicePlan; functionsApp ]
}