danielwertheim

danielwertheim


notes from a passionate developer

Share


Sections


Tags


Disclaimer

This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

Setting Daily usage quota for an Azure Function when using Terraform

I recently had the need of setting up an Azure Function using Terraform. For this particular environment I was using the consumption plan and wanted to make use of the "Daily Usage Quota" setting. This is not supported by the azurerm_function_app config/template. I filed a feature request for this on GitHub (feel free to upvote) and set out to find a working solution. Enter local-exec Provisioner Using it I could use the Azure CLI and set the property dailyMemoryTimeQuota

Looking something like this:

resource "null_resource" "fna_a_daily_quota" {
  provisioner "local-exec" {
    command = "az functionapp update -g ${azurerm_resource_group.rg.name} -n ${azurerm_function_app.fna_a.name} --set dailyMemoryTimeQuota=5000"
  }
}

Lets look at an extraction of the solution showing both the azurerm_function_app and the provisioner "local-exec".

resource "azurerm_function_app" "fna_a" {
  name                      = "${var.name}-fna"
  location                  = azurerm_resource_group.rg.location
  resource_group_name       = azurerm_resource_group.rg.name
  app_service_plan_id       = azurerm_app_service_plan.asp.id
  storage_connection_string = azurerm_storage_account.sta.primary_connection_string
  version                   = "~3"
  https_only                = true
  tags                      = var.tags
  app_settings = {
      FUNCTION_APP_EDIT_MODE                    = "readonly"
      FUNCTIONS_WORKER_RUNTIME                  = "dotnet"
      FUNCTIONS_WORKER_PROCESS_COUNT            = 1
      FUNCTIONS_EXTENSION_VERSION               = "~3"
      WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT = 1
      AzureWebJobsDisableHomepage               = true
      APPINSIGHTS_INSTRUMENTATIONKEY            = "${azurerm_application_insights.ai.instrumentation_key}"
  }
}

resource "null_resource" "fna_a_daily_quota" {
  provisioner "local-exec" {
    command = "az functionapp update -g ${azurerm_resource_group.rg.name} -n ${azurerm_function_app.fna_a.name} --set dailyMemoryTimeQuota=5000"
  }
}

After applying this the portal should look similar to this:

Hope it helps you in your quest of setting this property using Terraform. Feel free to guide me to a better solution.

//Daniel

View Comments