Skip to content

Instantly share code, notes, and snippets.

@thomd
Last active May 13, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomd/9f9dc8c3095ac3b0bd172ce8b4b74b6f to your computer and use it in GitHub Desktop.
Save thomd/9f9dc8c3095ac3b0bd172ce8b4b74b6f to your computer and use it in GitHub Desktop.
Azure Functions with Terraform #az #terraform
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.26"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "resource_group" {
name = "${var.project}-${var.environment}-resource-group"
location = var.location
}
resource "azurerm_storage_account" "storage_account" {
name = "${var.project}${var.environment}storage"
resource_group_name = azurerm_resource_group.resource_group.name
location = var.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_application_insights" "application_insights" {
name = "${var.project}-${var.environment}-application-insights"
location = var.location
resource_group_name = azurerm_resource_group.resource_group.name
application_type = "web"
}
resource "azurerm_app_service_plan" "app_service_plan" {
name = "${var.project}-${var.environment}-app-service-plan"
resource_group_name = azurerm_resource_group.resource_group.name
location = var.location
kind = "FunctionApp"
reserved = true
sku {
tier = "Dynamic"
size = "Y1"
}
}
resource "azurerm_function_app" "function_app" {
name = "${var.project}-${var.environment}-function-app"
resource_group_name = azurerm_resource_group.resource_group.name
location = var.location
app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
app_settings = {
"WEBSITE_RUN_FROM_PACKAGE" = "",
"APPINSIGHTS_INSTRUMENTATIONKEY" = azurerm_application_insights.application_insights.instrumentation_key,
}
os_type = "linux"
storage_account_name = azurerm_storage_account.storage_account.name
storage_account_access_key = azurerm_storage_account.storage_account.primary_access_key
version = "~3"
lifecycle {
ignore_changes = [
app_settings["WEBSITE_RUN_FROM_PACKAGE"],
]
}
}
output "function_app_name" {
value = azurerm_function_app.function_app.name
description = "Deployed function app name"
}
output "function_app_default_hostname" {
value = azurerm_function_app.function_app.default_hostname
description = "Deployed function app hostname"
}
project = "thomd"
environment = "dev"
location = "East US"
variable "project" {
type = string
description = "Project name"
}
variable "environment" {
type = string
description = "Environment (dev/stage/prod)"
}
variable "location" {
type = string
description = "Azure region"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment