Original Answer: 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.
UPDATE: With AzAPI Terraform provider [2], we could manage resources not presently supported by AzureRM provider. Code sample below for application settings and Azure function linkage to static web app.
# For AzAPI provider
terraform {
required_providers {
azapi = {
source = "azure/azapi"
version = "~> 1.0"
}
}
}
# For static web app
resource azurerm_static_site swa {
name = "myswa"
resource_group_name = "myrg"
location = "westeurope"
# ignore below if you do not need to link functions
sku_tier = "Standard"
sku_size = "Standard"
}
# For application settings. You may change to azapi_resource once Github issue
# https://github.com/Azure/terraform-provider-azapi/issues/256 is closed.
resource azapi_resource_action appsetting {
type = "Microsoft.Web/staticSites/config@2022-03-01"
resource_id = "${azurerm_static_site.swa.id}/config/appsettings"
method = "PUT"
body = jsonencode({
properties = {
"mykey"="myvalue"
}
})
}
# For linking Azure function. Ignore if not needed
resource azapi_resource linktofunction {
type = "Microsoft.Web/staticSites/userProvidedFunctionApps@2022-03-01"
name = "swalinktofunction"
parent_id = azurerm_static_site.swa.id
body = jsonencode({
properties = {
functionAppRegion = "westeurope"
# below swafunction created else where
functionAppResourceId = azurerm_windows_function_app.swafunction.id
}
})
}
For application settings, I was forced to use azapi_resource_action since azapi_resource was not working for issue [3]. This has an important consequence: if application settings is deleted or updated via external means like Azure portal or az cli, Terraform will not know about it. This is not ideal, but that is best we could get with Terraform for now.