forked from oracle-quickstart/appstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.tf
541 lines (478 loc) · 14 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# Copyright (c) 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
# variables
variable "tenancy_ocid" {}
variable "compartment_ocid" {}
variable "region" {}
variable "current_user_ocid" {}
# Compartment / availability domain
variable compartment_id {
description = "The selected comptartment, by default the users compartment"
type = string
}
variable "availability_domain" {
description = "Availabiliy domain"
type = string
}
variable "application_name" {
description = "Application name"
type = string
}
variable "exposed_port" {
description = "Exposed port"
type = string
default = "8443"
}
# Database configuration
variable "use_existing_database" {
type = bool
}
# Existing database
variable "autonomous_database" {
description = "Existing autonomous database"
type = string
default = "none"
}
# Database user
variable "autonomous_database_user" {
description = "Existing autonomous database user"
type = string
default = "none"
}
# Secret containing database user's password
variable "autonomous_database_password" {
description = "Existing autonomous database password"
type = string
default = ""
}
variable "autonomous_database_admin_password" {
description = "Existing autonomous database password"
type = string
default = ""
}
# New database
variable "autonomous_database_display_name" {
description = "Database display name"
type = string
default = "none"
}
# The vault where the admin password will be stored
variable "vault_compartment_id" {
description = "Compartment of the exiting vault"
type = string
}
variable "vault_id" {
description = "The vault where the database ADMIN password will be stored"
type = string
default = "none"
}
# Encryption key to be used when storing the ADMIN password
variable "key_id" {
description = "Encryption key used for storing the password"
type = string
default = "none"
}
# OCI devops repository
variable "repo_name" {
type = string
default = ""
}
# Branch
variable "branch" {
type = string
default = ""
}
# Build command
variable "build_command" {
type = string
default = ""
}
# Artifact location
variable "artifact_location" {
type = string
default = ""
}
# Number of copies
variable "nb_copies" {
type = number
}
variable "certificate_ocid" {
type = string
description = "Cerfificate ocid"
default = "none"
}
variable "subdomain" {
type = string
description = "DNS zone"
default = ""
}
variable "zone" {
type = string
description = "DNS zone"
default = ""
}
variable "application_source" {
type = string
description = "source of the application: IMAGE, JAR/WAR, source code"
}
variable "application_type" {
type = string
default = "not selected"
description = "application type : JAR, WAR"
}
variable "create_fqdn" {
type = bool
description = "create a FQDN that points to the load balancer"
}
# Application configuration environment variables
variable "connection_url_env" {
type = string
default = ""
}
variable "tns_admin_env" {
type = string
default = "TNS_ADMIN"
}
variable "username_env" {
type = string
default = ""
}
variable "password_env" {
type = string
default = ""
}
variable "use_connection_url_env" {
type = bool
default = false
}
variable "use_tns_admin_env" {
type = bool
default = false
}
variable "use_username_env" {
type = bool
default = false
}
variable "use_password_env" {
type = bool
default = false
}
# Application configuration - SSL properties
variable "use_default_ssl_configuration" {
type = bool
default = false
}
variable "port_property" {
type = string
default = "server.port"
}
variable "keystore_property" {
type = string
default = "server.ssl.key-store"
}
variable "key_alias_property" {
type = string
default = "server.ssl.key-alias"
}
variable "keystore_password_property" {
type = string
default = "server.ssl.key-store-password"
}
variable "keystore_type_property" {
type = string
default = "server.ssl.key-store-type"
}
# Network configuration CIDR
variable "vcn_compartment_id" {
type = string
default = ""
}
variable "create_new_vcn" {
type = bool
default = false
}
variable "existing_vcn_id" {
type = string
default = ""
}
variable "vcn_cidr" {
type = string
default = "0.0.0.0/0"
}
variable "use_existing_app_subnet" {
type = bool
default = false
}
variable "existing_app_subnet_id" {
type = string
default = ""
}
variable "app_subnet_cidr" {
type = string
default = "0.0.0.0/0"
}
variable "use_existing_db_subnet" {
type = bool
default = false
}
variable "existing_db_subnet_id" {
type = string
default = ""
}
variable "db_subnet_cidr" {
type = string
default = "0.0.0.0/0"
}
variable "use_existing_lb_subnet" {
type = bool
default = false
}
variable "existing_lb_subnet_id" {
type = string
default = ""
}
variable "lb_subnet_cidr" {
type = string
default = "0.0.0.0/0"
}
# Application artifict configuration
variable "artifact_id" {
type = string
default = ""
}
variable "registry_id" {
type = string
default = ""
}
# Application image configuration
variable "image_path" {
type = string
default = ""
}
# Container instances
variable "shape" {
type = string
default = "CI.Standard.E3.Flex"
}
variable "memory_in_gbs" {
type = number
default = "16"
}
variable "ocpus" {
type = number
default = 2
}
# Load balancer
variable "use_default_lb_configuration" {
type = bool
default = false
}
variable "maximum_bandwidth_in_mbps" {
type = number
default = 10
}
variable "minimum_bandwidth_in_mbps" {
type = number
default = 10
}
variable "health_checker_url_path" {
type = string
default = "/"
}
variable "health_checker_return_code" {
type = number
default = 200
}
# database
variable "data_storage_size_in_tbs" {
type = number
default = 1
}
# variable "cpu_core_count" {
# type = number
# default = 2
# }
variable "ocpu_count" {
type = number
default = 1
}
variable "open_https_port" {
type = bool
default = false
}
variable "env_variables" {
type = list(string)
description = "Environment variables"
default = ["CONN_URL", "USERNAME", "PASSWORD", "WALLET"]
}
variable "other_environment_variables" {
type = string
description = "Other envoronment variables"
default = ""
}
variable "vm_options" {
type = string
description = "VM options"
default = ""
}
variable "program_arguments" {
type = string
description = "Program arguments"
default = ""
}
variable "enable_session_affinity" {
type = bool
description = "Enable session affinity"
default = false
}
variable "session_affinity" {
type = string
description = "Session affinity"
default = "NONE"
}
variable "session_affinity_cookie_name" {
type = string
description = "Session affinity cookie name"
default = "X-Oracle-BMC-LBS-Route"
}
variable "cert_pem" {
type = string
description = "Certificate"
default = ""
}
variable "ca_pem" {
type = string
description = "CA Certificate"
default = ""
}
variable "private_key_pem" {
type = string
description = "Private key"
default = ""
}
variable "use_existing_vault" {
type = bool
description = "Use existing vault"
default = true
}
variable "new_vault_display_name" {
type = string
description = "Display name of the key vault"
default = ""
}
variable "is_free_tier" {
type = bool
description = "APM free tier"
default = false
}
locals {
# region_key
region_key = lower(data.oci_identity_regions.current_region.regions[0].key)
# namespace
namespace = "${data.oci_objectstorage_namespace.os_namespace.namespace}"
# Service username
service-username = "${var.application_name}-user"
# login, tenancy + username (DevOps)
login = "${data.oci_identity_tenancy.tenancy.name}/${local.service-username}"
# login, namespace + username (Container Registry)
login_container = "${local.namespace}/${local.service-username}"
# authentication token
app_auth_token = oci_identity_auth_token.auth_token.token
# Container registry url
container-registry-repo = "${local.region_key}.ocir.io"
# image name
image-name = "${var.application_name}-image"
# load balancer name
load-balancer-name = "${var.application_name}-lb"
# repository name
repository-name = lower("${var.application_name}-repository")
# instance name
instance-name = "${var.application_name}-instance"
# vcn name
vcn-name = "${var.application_name}-vcn"
# internet gateway name
internet-gateway-name = "${var.application_name}-internet-gateway"
# vcn DNS label
vcn-dns-label = "vcn${formatdate("MMDDhhmm", timestamp())}"
# subnet DNS label
subnet-dns-label = "sn${formatdate("MMDDhhmm", timestamp())}"
# full image path on registry
image-remote-tag = (!local.use-image
? "${local.container-registry-repo}/${local.namespace}/${local.repository-name}:${local.image-name}"
: var.image_path)
# bucket name
bucket_name = "${var.application_name}-bucket"
# dbconnection_api_key_pem = (
# length(data.oci_identity_api_keys.dbconnection_api_key.api_keys) == 0
# ? oci_identity_api_key.dbconnection_api_key[0].key_value
# : data.oci_identity_api_keys.dbconnection_api_key.api_keys[0].key_value
# )
config_repo_name = "${var.application_name}-config"
config_repo_url = (local.use-image
? ""
: replace(oci_devops_repository.config_repo[0].http_url, "https://", "https://${urlencode(local.login)}:${urlencode(oci_identity_auth_token.auth_token.token)}@"))
# database OCID
database_ocid = (var.use_existing_database ? var.autonomous_database : oci_database_autonomous_database.database[0].id)
# database username
username = (var.use_existing_database ? var.autonomous_database_user : "ADMIN")
# database password
password = (var.use_existing_database ? var.autonomous_database_password : var.autonomous_database_admin_password)
# connection string index to use 0 for mTLS 5 for TLS
conn_url_index = ((local.use-image ? 0 : 5))
# database connection string
connection_str = (
var.use_existing_database
? replace(replace(data.oci_database_autonomous_database.autonomous_database.connection_strings[0].profiles[local.conn_url_index].value, "description= ", "description="), "\"", "\\\"")
: replace(replace(oci_database_autonomous_database.database[0].connection_strings[0].profiles[local.conn_url_index].value, "description= ", "description="), "\"", "\\\"")
)
connection_url = (
var.use_existing_database
? replace(data.oci_database_autonomous_database.autonomous_database.connection_strings[0].profiles[local.conn_url_index].value, "description= ", "description=")
: replace(oci_database_autonomous_database.database[0].connection_strings[0].profiles[local.conn_url_index].value, "description= ", "description=")
)
# FQDN
domain_name = "${var.subdomain}.${var.zone}"
# Connection URL environment variable
connection_url_env = "ENV ${var.connection_url_env}=jdbc:oracle:thin:@${local.connection_str}"
# Database username environment variable
username_env = "ENV ${var.username_env}=${local.username}"
# Database password environment variable
password_env = "ENV ${var.password_env}=${local.password}"
# TNS admin environment variable
tns_admin_env = "ENV ${var.tns_admin_env}=/opt/app/wallet"
# use repository (source code in devops)
use-repository = (var.application_source == "SOURCE_CODE")
# use artifact (jar or war)
use-artifact = (var.application_source == "ARTIFACT")
# use image (container image)
use-image = (var.application_source == "IMAGE")
# project_id
project_id = (local.use-image ? oci_devops_project.deploy_image_project[0].id : (local.use-repository ? data.oci_devops_repository.devops_repository[0].project_id : oci_devops_project.project[0].id))
# filtered env variables
env_variables_list = [
for env in var.env_variables :
(env == "CONN_URL" ? {name : "${var.connection_url_env}", value : "jdbc:oracle:thin:@${local.connection_url}"} :
(env == "USERNAME" ? {name : "${var.username_env}", value : local.username} :
(env == "PASSWORD" ? {name : "${var.password_env}", value : local.password} :
(env == "WALLET" ? {name : "${var.tns_admin_env}", value : "/opt/app/wallet"} : null))))
if ((env == "CONN_URL" && var.use_connection_url_env) ||
(env == "USERNAME" && var.use_username_env) ||
(env == "PASSWORD" && var.use_password_env) ||
(env == "WALLET" && (var.use_tns_admin_env || !local.use-image)))]
# Convert list to map
env_variables = { for env in local.env_variables_list : env.name => env.value }
other_env_variables = (var.other_environment_variables != "" ? { for env in split(";", var.other_environment_variables) : split("=", env)[0] => split("=", env)[1] } : {})
deploy_artifact_path = "${var.application_name}-deploy-script"
deploy_artifact_version = "1.0.0"
vcn_id = (var.create_new_vcn ? oci_core_vcn.app_oci_core_vnc[0].id : var.existing_vcn_id)
app_subnet_id = (var.use_existing_app_subnet ? var.existing_app_subnet_id : oci_core_subnet.app_oci_core_subnet[0].id)
db_subnet_id = (var.use_existing_db_subnet ? var.existing_db_subnet_id : (var.use_existing_database ? "" : oci_core_subnet.db_oci_core_subnet[0].id))
lb_subnet_id = (var.use_existing_lb_subnet ? var.existing_lb_subnet_id : oci_core_subnet.lb_oci_core_subnet[0].id)
app_subnet_cidr = data.oci_core_subnet.app_subnet.cidr_block
db_subnet_cidr = (var.use_existing_database ? "" : data.oci_core_subnet.db_subnet[0].cidr_block)
lb_subnet_cidr = data.oci_core_subnet.lb_subnet.cidr_block
create_service_gateway = (length(data.oci_core_service_gateways.existing_service_gateways.service_gateways) == 0 ? true : false)
service_gateway = (local.create_service_gateway ? oci_core_service_gateway.service_gateway : data.oci_core_service_gateways.existing_service_gateways.service_gateways)
create_internet_gateway = (length(data.oci_core_internet_gateways.existing_internet_gateways.gateways) == 0 ? true : false)
internet_gateway = (local.create_internet_gateway ? oci_core_internet_gateway.app_oci_core_internet_gateway : data.oci_core_internet_gateways.existing_internet_gateways.gateways)
}