-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvariables.tf
254 lines (212 loc) · 6.43 KB
/
variables.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
variable "name" {
type = string
description = "The name of the web app."
}
variable "resource_group_name" {
type = string
description = "The name of an existing resource group to use for the web app."
}
variable "resource_group_location" {
type = string
description = "Location of an existing resource group to use for the web app."
}
variable "container_type" {
type = string
default = "docker"
description = "Type of container. The options are: `docker`, `compose` or `kube`."
}
variable "container_config" {
type = string
default = ""
description = "Configuration for the container. This should be YAML."
}
variable "container_image" {
type = string
default = ""
description = "Container image name. Example: `innovationnorway/python-hello-world:latest`."
}
variable "port" {
type = string
default = null
description = "The value of the expected container port number."
}
variable "enable_storage" {
type = string
default = "false"
description = "Mount an SMB share to the `/home/` directory."
}
variable "start_time_limit" {
type = number
default = 230
description = "Configure the amount of time (in seconds) the app service will wait before it restarts the container."
}
variable "command" {
type = string
default = ""
description = "A command to be run on the container."
}
variable "app_settings" {
type = map(string)
default = {}
description = "Set app settings. These are avilable as environment variables at runtime."
}
variable "secure_app_settings" {
type = map(string)
default = {}
description = "Set sensitive app settings. Uses Key Vault references as values for app settings."
}
variable "key_vault_id" {
type = string
default = ""
description = "The ID of an existing Key Vault. Required if `secure_app_settings` is set."
}
variable "always_on" {
type = bool
default = true
description = "Either `true` to ensure the web app gets loaded all the time, or `false` to to unload after being idle."
}
variable "https_only" {
type = bool
default = true
description = "Redirect all traffic made to the web app using HTTP to HTTPS."
}
variable "ftps_state" {
type = string
default = "Disabled"
description = "Set the FTPS state value the web app. The options are: `AllAllowed`, `Disabled` and `FtpsOnly`."
}
variable "ip_restrictions" {
type = list(string)
default = []
description = "A list of IP addresses in CIDR format specifying Access Restrictions."
}
variable "custom_hostnames" {
type = list(string)
default = []
description = "List of custom hostnames to use for the web app."
}
variable "docker_registry_username" {
type = string
default = null
description = "The container registry username."
}
variable "docker_registry_url" {
type = string
default = "https://index.docker.io"
description = "The container registry url."
}
variable "docker_registry_password" {
type = string
default = null
description = "The container registry password."
}
variable "plan" {
type = map(string)
default = {}
description = "A map of app service plan properties."
}
variable "identity" {
type = any
default = {}
description = "Managed service identity properties."
}
variable "storage_mounts" {
type = any
default = []
description = "List of storage mounts."
}
variable "auth" {
type = any
default = {}
description = "Auth settings for the web app. This should be `auth` object."
}
variable "tags" {
type = map(string)
default = {}
description = "A mapping of tags to assign to the web app."
}
locals {
app_settings = {
"WEBSITES_CONTAINER_START_TIME_LIMIT" = var.start_time_limit
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = var.enable_storage
"WEBSITES_PORT" = var.port
"DOCKER_REGISTRY_SERVER_USERNAME" = var.docker_registry_username
"DOCKER_REGISTRY_SERVER_URL" = var.docker_registry_url
"DOCKER_REGISTRY_SERVER_PASSWORD" = var.docker_registry_password
}
container_type = upper(var.container_type)
container_config = base64encode(var.container_config)
supported_container_types = {
COMPOSE = true
DOCKER = true
KUBE = true
}
check_supported_container_types = local.supported_container_types[local.container_type]
linux_fx_version = "${local.container_type}|${local.container_type == "DOCKER" ? var.container_image : local.container_config}"
ip_restrictions = [
for prefix in var.ip_restrictions : {
ip_address = split("/", prefix)[0]
subnet_mask = cidrnetmask(prefix)
}
]
key_vault_secrets = [
for name, value in var.secure_app_settings : {
name = replace(name, "/[^a-zA-Z0-9-]/", "-")
value = value
}
]
secure_app_settings = {
for secret in azurerm_key_vault_secret.main :
replace(secret.name, "-", "_") => format("@Microsoft.KeyVault(SecretUri=%s)", secret.id)
}
default_plan_name = format("%s-plan", var.name)
plan = merge({
id = ""
name = ""
sku_size = "S1"
}, var.plan)
plan_id = coalesce(local.plan.id, azurerm_app_service_plan.main[0].id)
# FIXME: create a data source that exports list of all SKUs.
sku_map = {
"Free" = ["F1", "Free"]
"Shared" = ["D1", "Shared"]
"Basic" = ["B1", "B2", "B3"]
"Standard" = ["S1", "S2", "S3"]
"Premium" = ["P1", "P2", "P3"]
"PremiumV2" = ["P1v2", "P2v2", "P3v2"]
}
skus = flatten([
for tier, sizes in local.sku_map : [
for size in sizes : {
tier = tier
size = size
}
]
])
sku_tiers = { for sku in local.skus : sku.size => sku.tier }
is_shared = contains(["F1", "FREE", "D1", "SHARED"], upper(local.plan.sku_size))
always_on = local.is_shared ? false : true
use_32_bit_worker_process = local.is_shared ? true : false
identity = merge({
enabled = true
ids = null
}, var.identity)
storage_mounts = [
for s in var.storage_mounts : merge({
name = ""
account_name = ""
access_key = ""
share_name = ""
container_name = ""
mount_path = ""
}, s)
]
auth = merge({
enabled = false
active_directory = {
client_id = ""
client_secret = ""
}
token_store_enabled = true
}, var.auth)
}