Created
September 14, 2020 14:45
-
-
Save JayDoubleu/59e01e843f9d82d4364e9de24228a484 to your computer and use it in GitHub Desktop.
terraform functionapp loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "azurerm" { | |
// subscription_id = "" | |
// tenant_id = "" | |
features {} | |
} | |
locals { | |
// some default/global settings here | |
default_location = "northeurope" | |
default_tags = {} | |
funcapp_default_resource_group = "rg-funkyfunctionappshere" | |
funcapp_default_app_service_plan_id = "" | |
funcapp_default_storage_connection_string = "" | |
// some functionapp specific settings here | |
function_apps = { | |
/// | |
functionapp_name_1 = { | |
name = "functionapp1" | |
enabled = true | |
location = local.default_location | |
resource_group_name = local.funcapp_default_resource_group | |
app_service_plan_id = local.funcapp_default_app_service_plan_id | |
storage_connection_string = local.funcapp_default_storage_connection_string | |
tags = local.default_tags | |
os_type = "linux" | |
APP_SETTINGS = { | |
"FUNCTIONS_WORKER_RUNTIME" = "python" | |
"WEBSITE_HTTPLOGGING_RETENTION_DAYS" = "30" | |
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "true" | |
"WEBSITE_ENABLE_SYNC_UPDATE_SITE" = "true" | |
"APPINSIGHTS_INSTRUMENTATIONKEY" = "APPINSIGHTS INSTRUMENTATIONKEY HERE" | |
"TZ" = "Europe/London" | |
"CUSTOM_SETTING_KEY_1" = "custom_setting_value_1" | |
"YOUR_SENSITIVE_SETTING_KEY" = "@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931)" | |
// In order to use KeyVault references the SystemAssigned identity needs to be enabled and IAM assigned - happy to explain at later date | |
// https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references | |
// | |
} | |
} | |
/// | |
/// | |
functionapp_name_2 = { | |
name = "functionapp2" | |
enabled = true | |
location = local.default_location | |
resource_group_name = local.funcapp_default_resource_group | |
app_service_plan_id = local.funcapp_default_app_service_plan_id | |
storage_connection_string = local.funcapp_default_storage_connection_string | |
tags = local.default_tags | |
os_type = "linux" | |
APP_SETTINGS = { | |
"FUNCTIONS_WORKER_RUNTIME" = "python" | |
"WEBSITE_HTTPLOGGING_RETENTION_DAYS" = "30" | |
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "true" | |
"WEBSITE_ENABLE_SYNC_UPDATE_SITE" = "true" | |
"APPINSIGHTS_INSTRUMENTATIONKEY" = "APPINSIGHTS INSTRUMENTATIONKEY HERE" | |
"TZ" = "Europe/London" | |
"CUSTOM_SETTING_KEY_1" = "custom_setting_value_1" | |
"YOUR_SENSITIVE_SETTING_KEY" = "@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931)" | |
// In order to use KeyVault references the SystemAssigned identity needs to be enabled and IAM assigned - happy to explain at later date | |
// https://docs.microsoft.com/en-us/azure/app-service/app-service-key-vault-references | |
// | |
} | |
} | |
/// | |
} | |
} | |
resource "azurerm_function_app" "mymultiapp" { | |
for_each = { | |
for functionapp in local.function_apps : | |
functionapp.name => functionapp | |
if functionapp.enabled == true | |
} | |
name = each.value.name | |
location = each.value.location | |
resource_group_name = each.value.resource_group_name | |
app_service_plan_id = each.value.app_service_plan_id | |
storage_connection_string = each.value.storage_connection_string | |
version = "~2" | |
tags = each.value.tags | |
os_type = each.value.os_type | |
enabled = each.value.enabled | |
https_only = true | |
identity { | |
type = "SystemAssigned" | |
} | |
app_settings = each.value.APP_SETTINGS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment