Skip to content

Commit

Permalink
Merge pull request #10 from habr-mms/add_static_site
Browse files Browse the repository at this point in the history
Add new resource static site
  • Loading branch information
michaelamattes authored Nov 24, 2022
2 parents 3829e81 + dc8aa13 commit efd359d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 7 deletions.
21 changes: 14 additions & 7 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,32 @@ 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 = {
service = "service_name"
}
}
}
static_site = {
swa-service-domain = {
location = "westeurope"
resource_group_name = "rg-service-env"
tags = {
service = "service-name"
}
}
}
}


21 changes: 21 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
28 changes: 28 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand All @@ -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) :
Expand Down Expand Up @@ -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])
}
)
}
}

0 comments on commit efd359d

Please sign in to comment.