From 0a05cfbbb6c365a3dca66d7c08a11986772d02a4 Mon Sep 17 00:00:00 2001 From: Hauke Brandt Date: Tue, 8 Nov 2022 07:47:35 +0100 Subject: [PATCH 1/3] Added resource static_site --- main.tf | 21 +++++++++++++++++++++ outputs.tf | 12 ++++++++++++ variables.tf | 28 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/main.tf b/main.tf index e63fad7..e8ee1c5 100644 --- a/main.tf +++ b/main.tf @@ -301,3 +301,24 @@ resource "azurerm_linux_function_app" "linux_function_app" { tags = local.linux_function_app[each.key].tags } + +resource "azurerm_static_site" "static_site" { + for_each = var.static_site + + name = local.static_site[each.key].name == "" ? each.key : local.static_site[each.key].name + location = local.static_site[each.key].location + resource_group_name = local.static_site[each.key].resource_group_name + sku_tier = local.static_site[each.key].sku_tier + sku_size = local.static_site[each.key].sku_size + + dynamic "identity" { + for_each = local.static_site[each.key].identity.type != "" ? [1] : [] + + content { + type = local.static_site[each.key].identity.type + identity_ids = local.static_site[each.key].identity.identity_ids + } + } + + tags = local.static_site[each.key].tags +} diff --git a/outputs.tf b/outputs.tf index 3811d59..0967140 100644 --- a/outputs.tf +++ b/outputs.tf @@ -20,3 +20,15 @@ output "linux_function_app" { } } } + +output "static-site" { + description = "azurerm_static_site results" + value = { + for static_site in keys(azurerm_static_site.static_site) : + static_site => { + id = azurerm_static_site.static_site[static_site].id + api_key = azurerm_static_site.static_site[static_site].api_key + default_host_name = azurerm_static_site.static_site[static_site].default_host_name + } + } +} diff --git a/variables.tf b/variables.tf index 7e08df6..2c78061 100644 --- a/variables.tf +++ b/variables.tf @@ -8,6 +8,11 @@ variable "linux_function_app" { default = {} description = "resource definition, default settings are defined within locals and merged with var settings" } +variable "static_site" { + type = any + default = {} + description = "resource definition, default settings are defined within locals and merged with var settings" +} locals { default = { @@ -188,6 +193,15 @@ locals { } tags = {} } + static_site = { + name = "" + sku_tier = "Standard" + sku_size = "Standard" + identity = { + type = "" + identity_ids = null + } + } } # compare and merge custom and default values @@ -207,6 +221,10 @@ locals { for linux_function_app in keys(var.linux_function_app) : linux_function_app => merge(local.default.linux_function_app.backup, local.linux_function_app_values[linux_function_app].backup) } + static_site_values = { + for static_site in keys(var.static_site) : + static_site => merge(local.default.static_site, var.static_site[static_site]) + } # merge all custom and default values linux_function_app = { for linux_function_app in keys(var.linux_function_app) : @@ -249,4 +267,14 @@ locals { for service_plan in keys(var.service_plan) : service_plan => merge(local.default.service_plan, var.service_plan[service_plan]) } + static_site = { + for static_site in keys(var.static_site) : + static_site => merge( + local.static_site_values[static_site], + { + for config in ["identity"] : + config => merge(local.default.static_site[config], local.static_site_values[static_site][config]) + } + ) + } } From 935d4f919c1992dbfb831524ecc752e32df10836 Mon Sep 17 00:00:00 2001 From: Hauke Brandt Date: Tue, 8 Nov 2022 07:50:49 +0100 Subject: [PATCH 2/3] Added example config for static_site --- examples/main.tf | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/main.tf b/examples/main.tf index f20193f..0d9ae9a 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -11,18 +11,18 @@ module "app_service" { } } linux_function_app = { - app-service-web = { - location = "westeurope" - resource_group_name = "service-env-rg" + app-service-web = { + location = "westeurope" + resource_group_name = "service-env-rg" service_plan_id = module.app_service.service_plan["spl-service-web"].id storage_account_name = module.storage.storage_account["service"].name storage_account_access_key = module.storage.storage_account["service"].primary_access_key functions_extension_version = "~3" https_only = false - app_settings = { + app_settings = { WEBSITE_NODE_DEFAULT_VERSION = "10.14.1" } - site_config = { + site_config = { always_on = true } tags = { @@ -30,6 +30,13 @@ module "app_service" { } } } + static_site = { + swa-service-domain = { + location = "westeurope" + resource_group_name = "rg-service-env" + tags = { + service = "service-name" + } + } + } } - - From dc8aa133a45dd683aac8861e793931e7ce8831fe Mon Sep 17 00:00:00 2001 From: Hauke Brandt Date: Wed, 16 Nov 2022 11:17:17 +0100 Subject: [PATCH 3/3] Corrected typo in outputs --- outputs.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/outputs.tf b/outputs.tf index 0967140..5c91b6a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -21,7 +21,7 @@ output "linux_function_app" { } } -output "static-site" { +output "static_site" { description = "azurerm_static_site results" value = { for static_site in keys(azurerm_static_site.static_site) :