quickstart/101-azure-functions/main.tf (63 lines of code) (raw):
# This Terraform configuration creates a Flex Consumption plan app in Azure Functions
# with the required Storage account and Blob Storage deployment container.
# Create a random pet to generate a unique resource group name
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}
# Create a resource group
resource "azurerm_resource_group" "example" {
location = var.resource_group_location
name = random_pet.rg_name.id
}
# Random String for unique naming of resources
resource "random_string" "name" {
length = 8
special = false
upper = false
lower = true
numeric = false
}
# Create a storage account
resource "azurerm_storage_account" "example" {
name = coalesce(var.sa_name, random_string.name.result)
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = var.sa_account_tier
account_replication_type = var.sa_account_replication_type
}
# Create a storage container
resource "azurerm_storage_container" "example" {
name = "example-flexcontainer"
storage_account_id = azurerm_storage_account.example.id
container_access_type = "private"
}
# Create a Log Analytics workspace for Application Insights
resource "azurerm_log_analytics_workspace" "example" {
name = coalesce(var.ws_name, random_string.name.result)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = "PerGB2018"
retention_in_days = 30
}
# Create an Application Insights instance for monitoring
resource "azurerm_application_insights" "example" {
name = coalesce(var.ai_name, random_string.name.result)
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
application_type = "web"
workspace_id = azurerm_log_analytics_workspace.example.id
}
# Create a service plan
resource "azurerm_service_plan" "example" {
name = coalesce(var.asp_name, random_string.name.result)
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku_name = "FC1"
os_type = "Linux"
}
# Create a function app
resource "azurerm_function_app_flex_consumption" "example" {
name = coalesce(var.fa_name, random_string.name.result)
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
service_plan_id = azurerm_service_plan.example.id
storage_container_type = "blobContainer"
storage_container_endpoint = "${azurerm_storage_account.example.primary_blob_endpoint}${azurerm_storage_container.example.name}"
storage_authentication_type = "StorageAccountConnectionString"
storage_access_key = azurerm_storage_account.example.primary_access_key
runtime_name = var.runtime_name
runtime_version = var.runtime_version
maximum_instance_count = 50
instance_memory_in_mb = 2048
site_config {
}
}