Jason Ashby
1 min readApr 5, 2021

--

Hi Matt, thanks for posting this. I found that you can do it all with terraform, i.e. without needing the func command. Here's some extra TF that will:

1. zip up the entire app function's local directory

2. push the zip to a storage container

3. tell Azure App Services to grab the function from the storage container (using the `WEBSITE_RUN_FROM_PACKAGE` app setting

The zip only happens when something under the function's local directory has changed.

```

locals {

my_function_dir_path = "${path.module}/../../../my-function-app"

zip_output_path = "${path.module}/my-function-app.zip"

}

# zip up the app

data "archive_file" "my_function_zip" {

type = "zip"

source_dir = local.my_function_dir_path

output_path = local.zip_output_path

# don't zip these files

excludes = [

"${local.my_function_dir_path}/local.settings.json",

"${local.my_function_dir_path}/.venv"

]

}

# Use a separate storage account for Functions

# See https://docs.microsoft.com/en-us/azure/azure-functions/storage-considerations

resource "azurerm_storage_account" "my_function" {

name = "myfunction"

resource_group_name = azurerm_resource_group.my_function.name

location = var.location

account_tier = "Standard"

account_replication_type = "LRS"

}

# Storage container where function zip is uploaded to

resource "azurerm_storage_container" "my_function" {

name = "my-function"

storage_account_name = azurerm_storage_account.my_function.name

container_access_type = "private"

}

resource "azurerm_storage_blob" "my_function_blob" {

name = "my-function.zip"

storage_account_name = azurerm_storage_account.my_function.name

storage_container_name = azurerm_storage_container.my_function.name

type = "Block"

source = local.zip_output_path

}

resource "azurerm_function_app" "my_function" {

...

app_settings = {

WEBSITE_RUN_FROM_PACKAGE = azurerm_storage_blob.my_function_blob.source_uri

}

...

}

```

--

--

Responses (1)