When you create a new Azure Function through the Azure portal, you will also be asked to create a new storage account for the app. The storage account is required for the app to operate normally because it stores necessary app data such as function code, app keys, and deployment logs in the storage (details here).

Secure the Storage through the Azure Portal
By default, the newly created storage account is publicly accessible and allows all incoming traffic, which may raise security concerns. To secure the storage, you can integrate the function app with a Virtual Network (*) and configure the storage to allow only VNet/Subnet. This tutorial, How to use a secured storage account with Azure Functions | Microsoft Learn, explains how to create a new secure storage account separately, and then update the application settings to point to the new storage. Alternatively, you can refer to that tutorial to secure the storage currently used by the function app during or after app creation.


* VNet integration is supported by most App Service Plans but not the Consumption plan. For details, check Azure Functions networking options.
Using ARM Template
While the above tutorial includes all the operations needed to secure the storage for Azure functions, it is not clear how to automate the deployment. Another thing is that when we try to deploy an Azure function with existing secure storage, the UI mandates a private endpoint for the storage, and there is no way to bypass it. In fact, we can secure the storage by allowing selected networks on the storage, without using a private endpoint, but the portal does not offer this option (as of January 2025).

To get a working template for deployment, we refer to the Azure Quickstart Templates on GitHub and remove all private endpoint related sections. With an existing Subnet and secure storage, the template below creates:
- A file share in the storage
- An application insight
- A premium app service plan
- A function app
- A network config (VNet integration) for the function app
(Note: The existing subnet need to delegate to Microsoft.Web/serverFarms)
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionAppName": {
"defaultValue": "YourFunctionAppName",
"type": "String",
"metadata": {
"description": "The name of the Azure Function app."
}
},
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "String",
"metadata": {
"description": "The location into which the resources should be deployed."
}
},
"functionWorkerRuntime": {
"defaultValue": "node",
"allowedValues": [
"dotnet",
"node",
"python",
"java"
],
"type": "String",
"metadata": {
"description": "The language worker runtime to load in the function app."
}
},
"functionPlanOS": {
"defaultValue": "Linux",
"allowedValues": [
"Windows",
"Linux"
],
"type": "String",
"metadata": {
"description": "Specifies the OS used for the Azure Function hosting plan."
}
},
"functionAppPlanSku": {
"defaultValue": "EP1",
"allowedValues": [
"EP1",
"EP2",
"EP3"
],
"type": "String",
"metadata": {
"description": "Specifies the Azure Function hosting plan SKU."
}
},
"functionAppPlanName": {
"defaultValue": "[format('plan-{0}', uniqueString(resourceGroup().id))]",
"type": "String",
"metadata": {
"description": "The name of the Azure Function hosting plan."
}
},
"functionStorageAccountName": {
"defaultValue": "YourStorageName",
"type": "String",
"metadata": {
"description": "The name of the backend Azure storage account used by the Azure Function app."
}
},
"vnetName": {
"defaultValue": "YourVNetName",
"type": "String",
"metadata": {
"description": "The name of the virtual network for virtual network integration."
}
},
"functionSubnetName": {
"defaultValue": "YourSubnetName",
"type": "String",
"metadata": {
"description": "The name of the virtual network subnet to be associated with the Azure Function app."
}
},
"linuxFxVersion": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "Only required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.9'"
}
}
},
"variables": {
"applicationInsightsName": "[format('appi-{0}', uniqueString(resourceGroup().id))]",
"functionContentShareName": "function-content-share",
"isReserved": "[if(equals(parameters('functionPlanOS'), 'Linux'), true(), false())]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2022-05-01",
"name": "[format('{0}/default/{1}', parameters('functionStorageAccountName'), variables('functionContentShareName'))]"
},
{
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02",
"name": "[variables('applicationInsightsName')]",
"location": "[parameters('location')]",
"kind": "web",
"properties": {
"Application_Type": "web"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2022-03-01",
"name": "[parameters('functionAppPlanName')]",
"location": "[parameters('location')]",
"sku": {
"tier": "ElasticPremium",
"name": "[parameters('functionAppPlanSku')]",
"size": "[parameters('functionAppPlanSku')]",
"family": "EP"
},
"kind": "elastic",
"properties": {
"maximumElasticWorkerCount": 20,
"reserved": "[variables('isReserved')]"
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2022-03-01",
"name": "[parameters('functionAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('applicationInsightsName'))]",
"[resourceId('Microsoft.Web/serverfarms', parameters('functionAppPlanName'))]"
],
"kind": "[if(variables('isReserved'), 'functionapp,linux', 'functionapp')]",
"properties": {
"reserved": "[variables('isReserved')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('functionAppPlanName'))]",
"siteConfig": {
"functionsRuntimeScaleMonitoringEnabled": true,
"linuxFxVersion": "[if(variables('isReserved'), parameters('linuxFxVersion'), json('null'))]",
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(resourceId('Microsoft.Insights/components', variables('applicationInsightsName')), '2020-02-02').InstrumentationKey]"
},
{
"name": "AzureWebJobsStorage",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('functionStorageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('functionStorageAccountName')), '2022-05-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('functionStorageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('functionStorageAccountName')), '2022-05-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[variables('functionContentShareName')]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~4"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "[parameters('functionWorkerRuntime')]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "~14"
},
{
"name": "WEBSITE_VNET_ROUTE_ALL",
"value": "1"
},
{
"name": "WEBSITE_CONTENTOVERVNET",
"value": "1"
}
]
}
}
},
{
"type": "Microsoft.Web/sites/networkConfig",
"apiVersion": "2022-03-01",
"name": "[format('{0}/{1}', parameters('functionAppName'), 'virtualNetwork')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
],
"properties": {
"subnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('functionSubnetName'))]",
"swiftSupported": true
}
}
]
}
The key here is that we need to create a file share in the storage for the function app. Moreover, the app settings must contain the connection information for the storage, such as:
AzureWebJobsStorage=<storage-connection-string>WEBSITE_CONTENTAZUREFILECONNECTIONSTRING=<storage-connection-string>WEBSITE_CONTENTSHARE=<file-share-name>WEBSITE_CONTENTOVERVNET=1
The app setting of WEBSITE_CONTENTOVERVNET=1 is equivalent to setting the site property vnetContentShareEnabled as true. This also means you enable the content storage checkbox in configuration routing.

Here is another example using a dedicated plan for the function app. With an existing dedicated app service plan, secure storage, and subnet, the template below creates:
- A file share in the storage
- A function app
- A network config (VNet integration) for the function app
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"functionAppName": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The name of the Azure Function app."
}
},
"location": {
"defaultValue": "West US 2",
"type": "String",
"metadata": {
"description": "The location into which the resources should be deployed."
}
},
"functionWorkerRuntime": {
"defaultValue": "node",
"allowedValues": [
"dotnet",
"node",
"python",
"java"
],
"type": "String",
"metadata": {
"description": "The language worker runtime to load in the function app."
}
},
"functionPlanOS": {
"defaultValue": "Linux",
"allowedValues": [
"Windows",
"Linux"
],
"type": "String",
"metadata": {
"description": "Specifies the OS used for the Azure Function hosting plan."
}
},
"functionStorageAccountName": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The name of the backend Azure storage account used by the Azure Function app."
}
},
"functionVnetName": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The name of the virtual network for virtual network integration."
}
},
"functionSubnetName": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The name of the virtual network subnet to be associated with the Azure Function app."
}
},
"linuxFxVersion": {
"defaultValue": "Node|20",
"type": "String",
"metadata": {
"description": "Only required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.9'"
}
},
"hostingPlanName": {
"type": "string"
}
},
"variables": {
"functionContentShareName": "function-content-share",
"isReserved": "[if(equals(parameters('functionPlanOS'), 'Linux'), true(), false())]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2022-05-01",
"name": "[format('{0}/default/{1}', parameters('functionStorageAccountName'), variables('functionContentShareName'))]"
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2022-03-01",
"name": "[parameters('functionAppName')]",
"location": "[parameters('location')]",
"dependsOn": [],
"kind": "[if(variables('isReserved'), 'functionapp,linux', 'functionapp')]",
"properties": {
"reserved": "[variables('isReserved')]",
"publicNetworkAccess": "Enabled",
"vnetRouteAllEnabled": true,
"httpsOnly": true,
"serverFarmId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"siteConfig": {
"linuxFxVersion": "[if(variables('isReserved'), parameters('linuxFxVersion'), json('null'))]",
"appSettings": [
{
"name": "AzureWebJobsStorage",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('functionStorageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('functionStorageAccountName')), '2022-05-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"value": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('functionStorageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('functionStorageAccountName')), '2022-05-01').keys[0].value)]"
},
{
"name": "WEBSITE_CONTENTSHARE",
"value": "[variables('functionContentShareName')]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~4"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "[parameters('functionWorkerRuntime')]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "~14"
},
{
"name": "WEBSITE_CONTENTOVERVNET",
"value": "1"
}
]
}
}
},
{
"type": "Microsoft.Web/sites/networkConfig",
"apiVersion": "2022-03-01",
"name": "[format('{0}/{1}', parameters('functionAppName'), 'virtualNetwork')]",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
],
"properties": {
"subnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('functionVnetName'), parameters('functionSubnetName'))]",
"swiftSupported": true
}
}
]
}
Using Terraform
The required resources and arguments for Terraform to deploy a new function app with secure storage are similar to those in the ARM templates. The Terraform code below is a minimal working example that takes an existing resource group, VNet and Subnet as data, and creates:
- A storage,
azurerm_storage_account, with network_rules to secure the storage - A file share,
azurerm_storage_share, in the storage - A new premium app service plan,
azurerm_service_plan - A Linux/Node.js function app,
azurerm_linux_function_app, using the storage, file share, and service plan
provider "azurerm" {
features {}
subscription_id = "<your-subscription-id>"
}
data "azurerm_resource_group" "your_resource_group" {
name = "<your-resource-group-name>"
}
data "azurerm_virtual_network" "your_vnet" {
name = "<your-vnet-name>"
resource_group_name = data.azurerm_resource_group.your_resource_group.name
}
data "azurerm_subnet" "your_subnet" {
name = "<your-subnet-name>"
virtual_network_name = data.azurerm_virtual_network.your_vnet.name
resource_group_name = data.azurerm_resource_group.your_resource_group.name
}
resource "azurerm_storage_account" "your_storage" {
name = "<your-storage-name>"
resource_group_name = data.azurerm_resource_group.your_resource_group.name
location = data.azurerm_resource_group.your_resource_group.location
account_tier = "Standard"
account_replication_type = "LRS"
public_network_access_enabled = true
min_tls_version = "TLS1_2"
network_rules {
default_action = "Deny"
virtual_network_subnet_ids = [
data.azurerm_subnet.your_subnet.id
]
# ip_rules = ["<ip1-to-whitelist>", "<ip2-to-whitelist>", ...]
bypass = ["AzureServices"]
}
allow_nested_items_to_be_public = false
}
resource "azurerm_storage_share" "your_share" {
name = "<your-share-name>"
storage_account_id = azurerm_storage_account.your_storage.id
quota = 50
}
resource "azurerm_service_plan" "your_asp" {
name = "<your-asp-name>"
resource_group_name = data.azurerm_resource_group.your_resource_group.name
location = data.azurerm_resource_group.your_resource_group.location
os_type = "Linux"
sku_name = "EP1" # Premium plan for VNet integration
}
resource "azurerm_linux_function_app" "your_function_app" {
name = "<your-function-app-name>"
resource_group_name = data.azurerm_resource_group.your_resource_group.name
location = data.azurerm_resource_group.your_resource_group.location
service_plan_id = azurerm_service_plan.your_asp.id
storage_account_name = azurerm_storage_account.your_storage.name
storage_account_access_key = azurerm_storage_account.your_storage.primary_access_key
virtual_network_subnet_id = data.azurerm_subnet.your_subnet.id
site_config {
application_stack {
node_version = "20"
}
}
identity {
type = "SystemAssigned"
}
app_settings = {
WEBSITE_RUN_FROM_PACKAGE = "1"
"WEBSITE_CONTENTSHARE" = azurerm_storage_share.your_share.name
"WEBSITE_CONTENTOVERVNET" = "1"
}
lifecycle {
ignore_changes = [
app_settings,
site_config[0].application_stack,
zip_deploy_file # Ignore deployment package changes
]
}
}Sign into Azure with az login and run the above code with Terraform CLI. You will see the resources created successfully.
C:\Users\jim\tf>terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/azurerm...
- Installing hashicorp/azurerm v4.16.0...
- Installed hashicorp/azurerm v4.16.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
--
C:\Users\jim\tf>terraform plan
data.azurerm_resource_group.your_resource_group: Reading...
data.azurerm_resource_group.your_resource_group: Read complete after 0s
data.azurerm_virtual_network.your_vnet: Reading...
...
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# azurerm_linux_function_app.your_function_app will be created
+ resource "azurerm_linux_function_app" "your_function_app" {
...
Plan: 4 to add, 0 to change, 0 to destroy.
--
C:\Users\jim\tf>terraform apply
data.azurerm_resource_group.your_resource_group: Reading...
data.azurerm_resource_group.your_resource_group: Read complete after 1s data.azurerm_virtual_network.your_vnet: Reading...
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# azurerm_linux_function_app.your_function_app will be created
+ resource "azurerm_linux_function_app" "your_function_app" {
...
Plan: 4 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
azurerm_service_plan.your_asp: Creating...
azurerm_storage_account.your_storage: Creating...
azurerm_storage_account.your_storage: Still creating... [10s elapsed]
...
azurerm_storage_account.your_storage: Creation complete after 1m22s
azurerm_linux_function_app.your_function_app: Creating...
azurerm_linux_function_app.your_function_app: Still creating... [10s elapsed]
...
azurerm_linux_function_app.your_function_app: Creation complete after 1m29s
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.
Appendix: Function App Errors Related to the Storage
Here are storage-related errors (i.e., when the function app or the storage is incorrectly configured and the app has trouble connecting to the storage) I have seen:
- Unable to renew the function’s App Key
- The Code + Test feature does not work, or the UI cannot load the code
- The Test/Run of the functions returns HTTP 500 Internal Server Error
- Deployment-related errors, such as:
- The Kudu site does not work correctly; e.g., some folders or logs cannot display
- The deployment returns errors like Failed to deploy web package to App Service. Internal Server Error (CODE: 500)
- Unable to check the deployment logs in Azure Portal
- Terraform deployment error:
performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with response: {"Code":"BadRequest","Message":"Creation of storage file share failed with: 'The remote server returned an error: (403) Forbidden.'. Please check if the storage account is accessible."- The root cause is that the pipeline tried to create a file share automatically in the storage but got blocked. To resolve that, we define the file share in the terraform code, and put the file share name in app settings, with
"WEBSITE_CONTENTOVERVNET"="1"to route traffic between the app and content share through the VNet
- The root cause is that the pipeline tried to create a file share automatically in the storage but got blocked. To resolve that, we define the file share in the terraform code, and put the file share name in app settings, with
Sometimes, it is hard to associate the above errors with the storage, and you might be surprised when you identify the root cause.
