forked from claranet/terraform-azurerm-function-app-single
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locals.tf
96 lines (85 loc) · 3.79 KB
/
locals.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
locals {
default_tags = {
env = var.environment
stack = var.stack
}
linux_version_map = {
"linux" = {
"v2" = {
python = "DOCKER|mcr.microsoft.com/azure-functions/python:2.0-python3.6"
node = "DOCKER|mcr.microsoft.com/azure-functions/node:2.0-node8"
dotnet = "DOCKER|mcr.microsoft.com/azure-functions/dotnet:2.0"
},
"v3" = {
python = "DOCKER|mcr.microsoft.com/azure-functions/python:3.0-python3.8"
node = "DOCKER|mcr.microsoft.com/azure-functions/node:3.0-node12"
dotnet = "DOCKER|mcr.microsoft.com/azure-functions/dotnet:3.0"
}
},
"functionapp" = {
"v2" = {
python = "python|3.7"
node = "node|10"
dotnet = "dotnet|2.2"
},
"v3" = {
python = "python|3.8"
node = "node|12"
dotnet = "dotnet|3.1"
}
}
}
plan_kind = data.azurerm_app_service_plan.plan.kind
linux_fx_version = try(local.linux_version_map[lower(data.azurerm_app_service_plan.plan.kind)]["v${var.function_app_version}"][lower(var.function_language_for_linux)], "")
default_site_config = {
always_on = data.azurerm_app_service_plan.plan.sku[0].tier == "Dynamic" ? false : true
linux_fx_version = local.linux_fx_version
ip_restriction = concat(local.subnets, local.cidrs)
}
name_prefix = var.name_prefix != "" ? replace(var.name_prefix, "/[a-z0-9]$/", "$0-") : ""
ai_name_prefix = var.application_insights_name_prefix != "" ? replace(var.application_insights_name_prefix, "/[a-z0-9]$/", "$0-") : local.name_prefix
function_name_prefix = var.function_app_name_prefix != "" ? replace(var.function_app_name_prefix, "/[a-z0-9]$/", "$0-") : local.name_prefix
sa_name_prefix = var.storage_account_name_prefix != "" ? replace(var.storage_account_name_prefix, "/[a-z0-9]$/", "$0-") : local.name_prefix
function_default_name = "${local.function_name_prefix}${var.stack}-${var.client_name}-${var.location_short}-${var.environment}-func"
application_insights_default_name = "${local.ai_name_prefix}${var.stack}-${var.client_name}-${var.location_short}-${var.environment}-ai"
storage_default_name_long = replace(
format(
"%s%s%s",
local.sa_name_prefix,
var.stack,
var.environment,
),
"/[._-]/",
"",
)
storage_default_name = substr(
local.storage_default_name_long,
0,
length(local.storage_default_name_long) > 24 ? 23 : -1,
)
app_insights = try(data.azurerm_application_insights.app_insights.0, try(azurerm_application_insights.app_insights.0, {}))
default_application_settings = merge({
FUNCTIONS_WORKER_RUNTIME = var.function_language_for_linux
}, var.application_insights_enabled ? {
APPLICATION_INSIGHTS_IKEY = try(local.app_insights.instrumentation_key, "")
APPINSIGHTS_INSTRUMENTATIONKEY = try(local.app_insights.instrumentation_key, "")
APPLICATIONINSIGHTS_CONNECTION_STRING = try(local.app_insights.connection_string, "")
} : {}
)
cidrs = [for cidr in var.authorized_ips : {
name = "ip_restriction_cidr_${join("", [1, index(var.authorized_ips, cidr)])}"
ip_address = cidr
virtual_network_subnet_id = null
subnet_id = null
priority = join("", [1, index(var.authorized_ips, cidr)])
action = "Allow"
}]
subnets = [for subnet in var.authorized_subnet_ids : {
name = "ip_restriction_subnet_${join("", [1, index(var.authorized_subnet_ids, subnet)])}"
ip_address = null
virtual_network_subnet_id = subnet
subnet_id = subnet
priority = join("", [1, index(var.authorized_subnet_ids, subnet)])
action = "Allow"
}]
}