Azure Static Web App - Application Settings using Terraform

Viewed 1392

Using Terraform, I created an Azure Static Web App as below. But the documentation does not demonstrate how to set application settings for the resource. For normal Azure functions apps we can see app_settings parameter. But how to set app settings for azure static web app created using Terraform?

resource "azurerm_static_site" "example" {
  name                = "example"
  resource_group_name = "example"
  location            = "West Europe"
}

I like to set parameters AAD_CLIENT_ID and AAD_CLIENT_SECRET to configure identity provider for the azure static web app as in microsoft documention.

2 Answers

Application settings on Azure static web apps is an open feature request as of now (24/Nov/2021). I will update this answer as the feature is added to Terraform.

I believe in looking at the Terraform documentation (Link: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/static_site) which you have looked at, the static web app is very basic, and doesn't take app settings arguments.

Also according to the Azure Blog: https://devblogs.microsoft.com/devops/comparing-azure-static-web-apps-vs-azure-webapps-vs-azure-blob-storage-static-sites/ If you have a web app that you want to do more than just host a static site then you need to use a full featured web app. Perhaps Hashi Corp has taken that to mean this is essentially a basic web app to host a front end page? Not sure...

Following this theory, to do app Settings in Terraform you need to make an Azure Web App by the looks of things:

Here is an example of one I have if you need any guidance on how to code a Web App with App Settings. You probably know but for ref here you go.

resource "azurerm_app_service_plan" "websiteappserviceplan" {
  name                = "appserviceplan_mysite"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  sku {
    tier = "Basic"
    size = "B1"
  }
}

resource "azurerm_app_service" "web_app" { 
  name                = var.webapp_name
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  app_service_plan_id = azurerm_app_service_plan.websiteappserviceplan.id


  app_settings = {
    "KEY_VAULT_URL"             = azurerm_key_vault.myvault.vault_uri
    "SUPPORTS_SAFEGUARDING"     = "1"
    "SUPPORTS_TECHNICIAN"       = "1"
  }

  client_affinity_enabled = true

  site_config {
    always_on                 = true
    min_tls_version           = "1.2"
    dotnet_framework_version  = "v5.0"
    app_command_line          = "dotnet EventManagement.Web.dll"
    ftps_state                = "Disabled"
    use_32_bit_worker_process = true
    http2_enabled             = true
    websockets_enabled        = true
  }

  logs {
    detailed_error_messages_enabled = true
    failed_request_tracing_enabled  = true
    application_logs {
      azure_blob_storage {
        level             = "Information"
        sas_url           = format("https://${azurerm_storage_account.website_log_storage.name}.blob.core.windows.net/${azurerm_storage_container.website_logs_container.name}%s", data.azurerm_storage_account_blob_container_sas.website_logs_container_sas.sas)
        retention_in_days = 365
      }
    }

    http_logs {
      azure_blob_storage {
        sas_url           = format("https://${azurerm_storage_account.website_log_storage.name}.blob.core.windows.net/${azurerm_storage_container.website_logs_container.name}%s", data.azurerm_storage_account_blob_container_sas.website_logs_container_sas.sas)
        retention_in_days = 365
      }
    }

  }

  connection_string {
    name  = "StorageAccount"
    type  = "Custom"
    value = azurerm_storage_account.website_log_storage.primary_connection_string
  }

  identity {
    type = "SystemAssigned"
  }
}

Related