forked from shibayan/terraform-azurerm-keyvault-acmebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
160 lines (133 loc) · 4.41 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
data "azurerm_subnet" "acme_subnet" {
name = "acme_subnet"
virtual_network_name = "ADAPT_vnet"
resource_group_name = "adapt_common"
}
resource "azurerm_storage_account" "storage" {
name = "st${replace(lower(var.app_base_name), "/[^a-z0-9]/", "")}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
account_kind = "Storage"
account_tier = "Standard"
account_replication_type = "LRS"
enable_https_traffic_only = true
allow_nested_items_to_be_public = false
min_tls_version = "TLS1_2"
lifecycle {
ignore_changes = [
tags
]
}
}
resource "azurerm_service_plan" "serverfarm" {
name = "plan-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
os_type = "Windows"
sku_name = "B1"
lifecycle {
ignore_changes = [
tags
]
}
}
resource "azurerm_log_analytics_workspace" "workspace" {
name = "log-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
sku = "PerGB2018"
retention_in_days = 30
lifecycle {
ignore_changes = [
tags
]
}
}
resource "azurerm_application_insights" "insights" {
name = "appi-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
application_type = "web"
workspace_id = azurerm_log_analytics_workspace.workspace.id
lifecycle {
ignore_changes = [
tags
]
}
}
resource "azurerm_windows_function_app" "function" {
name = "func-${var.app_base_name}"
resource_group_name = var.resource_group_name
location = var.location
tags = var.additional_tags
service_plan_id = azurerm_service_plan.serverfarm.id
storage_account_name = azurerm_storage_account.storage.name
storage_account_access_key = azurerm_storage_account.storage.primary_access_key
functions_extension_version = "~4"
https_only = true
virtual_network_subnet_id = data.azurerm_subnet.acme_subnet.id
app_settings = merge({
"WEBSITE_RUN_FROM_PACKAGE" = "https://stacmebotprod.blob.core.windows.net/keyvault-acmebot/v4/latest.zip"
"WEBSITE_TIME_ZONE" = var.time_zone
}, local.acmebot_app_settings, local.auth_app_settings, var.additional_app_settings)
dynamic "sticky_settings" {
for_each = toset(length(local.auth_app_settings) != 0 ? [1] : [])
content {
app_setting_names = keys(local.auth_app_settings)
}
}
identity {
type = "SystemAssigned"
}
dynamic "auth_settings_v2" {
for_each = toset(var.auth_settings != null ? [1] : [])
content {
auth_enabled = var.auth_settings.enabled
default_provider = "azureactivedirectory"
require_authentication = true
unauthenticated_action = "RedirectToLoginPage"
login {
token_store_enabled = false
}
active_directory_v2 {
client_id = var.auth_settings.active_directory.client_id
client_secret_setting_name = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"
tenant_auth_endpoint = var.auth_settings.active_directory.tenant_auth_endpoint
}
}
}
site_config {
application_insights_connection_string = azurerm_application_insights.insights.connection_string
ftps_state = "Disabled"
minimum_tls_version = "1.2"
always_on = true
vnet_route_all_enabled = true
application_stack {
dotnet_version = "v6.0"
}
dynamic "ip_restriction" {
for_each = var.allowed_ip_addresses
content {
ip_address = ip_restriction.value
}
}
}
lifecycle {
ignore_changes = [
tags,
app_settings["MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"],
sticky_settings["app_setting_names"]
]
}
}
data "azurerm_function_app_host_keys" "function" {
name = azurerm_windows_function_app.function.name
resource_group_name = var.resource_group_name
depends_on = [
azurerm_windows_function_app.function
]
}