In previous articles (I, II) we’ve seen how to deploy an Azure Function App using the Azure CLI and the Azure Functions Core Tools. In this article we’ll see how to deploy it using Terraform.


In order to follow this article you will need the .Net SDK 2.1, the Azure CLI and Terraform installed in your laptop/container/VM/whatever.

Building the package

What Terraform is going to do is take advantage of the Zip deployment capability (More on this in a future article). So, what we need to do first is to create a zip with the contents we’d like to deploy. We’ll call this zip To do that, you can use this script:

dotnet publish
pushd bin/Debug/netcoreapp2.1/publish
zip -r -X ../../../../ *

Create the Terraform script

Let’s start creating the terraform script. Create a folder in your project called infrastructure and create file called, for example, Open the file to edit its contents.

The first thing we’ll need to do is specify the Resource Group we’d like to create:

resource "azurerm_resource_group" "rg-testDeployTF" {
  name     = "rg-testDeployTF"
  location = "westeurope"

Then, we need to specify the Storage Account:

resource "azurerm_storage_account" "sa-testDeployTF" {
  name                     = "testdeploytfsa"
  resource_group_name      = "${}"
  location                 = "${azurerm_resource_group.rg-testDeployTF.location}"
  account_tier             = "Standard"
  account_replication_type = "LRS"

It’s time to specify the Service Plan:

resource "azurerm_app_service_plan" "sp-testDeployTF" {
  name                = "sp-testDeployTF"
  location            = "${azurerm_resource_group.rg-testDeployTF.location}"
  resource_group_name = "${}"
  kind                = "FunctionApp"

  sku {
    tier = "Dynamic"
    size = "Y1"

Now it’s time to update the recently created zip file into a blob. We’d need to create a blob inside a storage container:

resource "azurerm_storage_container" "sc-testDeployTF" {
  name                  = "function-releases"
  resource_group_name   = "${}"
  storage_account_name  = "${}"
  container_access_type = "private"

resource "azurerm_storage_blob" "sb-testDeployTF" {
  name = ""

  resource_group_name    = "${}"
  storage_account_name   = "${}"
  storage_container_name = "${}"

  type   = "block"
  source = "./../"

In order that the Function App has access to this blob, we need to create a Shared Access Signature:

data "azurerm_storage_account_sas" "sas-testDeployTF" {
  connection_string = "${}"
  https_only        = false

  resource_types {
    service   = false
    container = false
    object    = true

  services {
    blob  = true
    queue = false
    table = false
    file  = false

  start  = "2018-03-21"
  expiry = "2028-03-21"

  permissions {
    read    = true
    write   = false
    delete  = false
    list    = false
    add     = false
    create  = false
    update  = false
    process = false

And finally we need to create the Function App and tell it that it needs to take the code from the uploaded zip file:

resource "azurerm_function_app" "testDeployTF" {
  name                      = "testDeployTF"
  location                  = "${azurerm_resource_group.rg-testDeployTF.location}"
  resource_group_name       = "${}"
  app_service_plan_id       = "${}"
  storage_connection_string = "${}"

  app_settings {
    HASH            = "${base64sha256(file("./../"))}"
    WEBSITE_USE_ZIP = "https://${}${}/${}${}"


It’s time to cd into the infrastructure folder, login into azure using az login and type terraform apply.

Azure Function Terraform

Here it is! The Function App deployed into Azure :-)


In this article we’ve seen how we can deploy a Function App using Terraform.