Azure Function App
This Terraform feature creates an Azure Function App. A Storage Account and an Application Insights are required and are created if not provided. An App Service Plan must be provided for hosting.
Version compatibility
| Module version | Terraform version | AzureRM version |
|---|---|---|
| >= 3.x.x | 0.12.x | >= 2.0 |
| >= 2.x.x | 0.12.x | < 2.0 |
| < 2.x.x | 0.11.x | < 2.0 |
Usage
This module is optimized to work with the Claranet terraform-wrapper tool which set some terraform variables in the environment needed by this module.
More details about variables set by the terraform-wrapper available in the documentation.
Here's 2 examples combined with the function-app-with-plan feature in order to have 2 functions on a dedicated App Service Plan.
Windows
module "azure-region" {
source = "claranet/regions/azurerm"
version = "x.x.x"
azure_region = var.azure_region
}
module "rg" {
source = "claranet/rg/azurerm"
version = "x.x.x"
azure_region = module.azure-region.location
client_name = var.client_name
environment = var.environment
stack = var.stack
}
module "function-plan" {
source = "claranet/app-service-plan/azurerm"
version = "x.x.x"
location = module.azure-region.location
location_short = module.azure-region.location_short
client_name = var.client_name
environment = var.environment
stack = var.stack
resource_group_name = module.rg.resource_group_name
kind = "Windows"
sku = {
size = "S1"
tier = "Standard"
}
}
module "function1" {
source = "claranet/function-app-single/azurerm"
version = "x.x.x"
location = module.azure-region.location
location_short = module.azure-region.location_short
client_name = var.client_name
environment = var.environment
stack = var.stack
resource_group_name = module.rg.resource_group_name
function_app_name_prefix = "function2"
app_service_plan_id = module.function-plan.app_service_plan_id
function_app_application_settings = {
"tracker_id" = "AJKGDFJKHFDS"
"backend_api_url" = "https://backend.domain.tld/api"
}
}Linux
module "azure-region" {
source = "claranet/regions/azurem"
version = "x.x.x"
azure_region = var.azure_region
}
module "rg" {
source = "claranet/rg/azurerm"
version = "x.x.x"
azure_region = module.azure-region.location
client_name = var.client_name
environment = var.environment
stack = var.stack
}
module "function-plan" {
source = "claranet/app-service-plan/azurerm"
version = "x.x.x"
location = module.azure-region.location
location_short = module.azure-region.location_short
client_name = var.client_name
environment = var.environment
stack = var.stack
resource_group_name = module.rg.resource_group_name
kind = "Linux"
sku = {
size = "S1"
tier = "Standard"
}
}
module "function1" {
source = "claranet/function-app-single/azurerm"
location = module.azure-region.location
location_short = module.azure-region.location_short
client_name = var.client_name
environment = var.environment
stack = var.stack
resource_group_name = module.rg.resource_group_name
function_app_name_suffix = "function2"
function_language_for_linux = "python"
app_service_plan_id = module.function-plan.app_service_plan_id
}
module "function-app" {
source = "claranet/function-app-single/azurerm"
version = "x.x.x"
location = module.azure-region.location
location_short = module.azure-region.location_short
client_name = var.client_name
environment = var.environment
stack = var.stack
resource_group_name = module.rg.resource_group_name
function_app_name_prefix = "armv2"
storage_account_name = "MyStorageName"
app_service_plan_id = module.function-plan.app_service_plan_id
identity_type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.myIdentity.id]
function_app_application_settings = {
"tracker_id" = "AJKGDFJKHFDS"
"backend_api_url" = "https://backend.domain.tld/api"
}
resource "azurerm_user_assigned_identity" "myIdentity" {
resource_group_name = module.rg.resource_group_name
location = module.azure-region.location
name = "MyManagedIdentity"
}
}Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| app_service_plan_id | Id of the App Service Plan for Function App hosting | string |
n/a | yes |
| application_insights_extra_tags | Extra tags to add to Application Insights | map(string) |
{} |
no |
| application_insights_instrumentation_key | Application Insights instrumentation key for function logs, generated if null | string |
null |
no |
| application_insights_name_prefix | Application Insights name prefix | string |
"" |
no |
| application_insights_type | Application Insights type if need to be generated | string |
"web" |
no |
| client_name | n/a | string |
n/a | yes |
| environment | n/a | string |
n/a | yes |
| extra_tags | Extra tags to add | map(string) |
{} |
no |
| function_app_application_settings | Function App application settings | map(string) |
{} |
no |
| function_app_extra_tags | Extra tags to add to Function App | map(string) |
{} |
no |
| function_app_name_prefix | Function App name prefix | string |
"" |
no |
| function_app_version | Version of function app to use | number |
2 |
no |
| function_language_for_linux | Language of the Function App on Linux hosting, can be "dotnet", "node" or "python" | string |
"dotnet" |
no |
| identity_ids | UserAssigned Identities ID to add to Function App. Mandatory if type is UserAssigned | list(string) |
null |
no |
| identity_type | Add an Identity (MSI) to the function app. Possible values are SystemAssigned or UserAssigned | string |
null |
no |
| location | Azure location for App Service Plan. | string |
n/a | yes |
| location_short | Short string for Azure location. | string |
n/a | yes |
| name_prefix | Name prefix for all resources generated name | string |
"" |
no |
| os_type | A string indicating the Operating System type for this function app. | string |
null |
no |
| resource_group_name | n/a | string |
n/a | yes |
| stack | n/a | string |
n/a | yes |
| storage_account_enable_advanced_threat_protection | Boolean flag which controls if advanced threat protection is enabled, see here for more information. | bool |
false |
no |
| storage_account_enable_https_traffic_only | Boolean flag which controls if https traffic only is enabled. | bool |
true |
no |
| storage_account_extra_tags | Extra tags to add to Storage Account | map(string) |
{} |
no |
| storage_account_kind | Storage Account Kind | string |
"StorageV2" |
no |
| storage_account_name | Name of the Storage account to attach to function | string |
null |
no |
| storage_account_name_prefix | Storage Account name prefix | string |
"" |
no |
| storage_account_primary_access_key | Primary access key the storage account to use. If null a new storage account is created | string |
null |
no |
Outputs
| Name | Description |
|---|---|
| app_service_plan_id | Id of the created App Service Plan |
| application_insights_app_id | App id of the associated Application Insights, empty if instrumentation key is provided |
| application_insights_id | Id of the associated Application Insights, empty if instrumentation key is provided |
| application_insights_instrumentation_key | Instrumentation key of the associated Application Insights |
| application_insights_name | Name of the associated Application Insights, empty if instrumentation key is provided |
| function_app_connection_string | Connection string of the created Function App |
| function_app_id | Id of the created Function App |
| function_app_identity | Identity block output of the Function App |
| function_app_name | Name of the created Function App |
| function_app_outbound_ip_addresses | Outbound IP adresses of the created Function App |
| storage_account_id | Id of the associated Storage Account, empty if connection string provided |
| storage_account_name | Name of the associated Storage Account, empty if connection string provided |
| storage_account_primary_access_key | Primary connection string of the associated Storage Account, empty if connection string provided |
| storage_account_primary_connection_string | Primary connection string of the associated Storage Account, empty if connection string provided |
| storage_account_secondary_access_key | Secondary connection string of the associated Storage Account, empty if connection string provided |
| storage_account_secondary_connection_string | Secondary connection string of the associated Storage Account, empty if connection string provided |
Related documentation
Microsoft Azure Functions documentation: github.com/Azure/Azure-Functions#documentation-1
Microsoft Managed Identities documentation: docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
