-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
95 lines (79 loc) · 2.52 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
module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.5"
existing_resource_group_name = var.existing_resource_group
}
resource "random_string" "prefix" {
length = 4
special = false
upper = false
numeric = false
}
resource "random_string" "admin_password" {
length = 32
special = false
}
resource "random_string" "rb_master_token" {
length = 32
special = false
}
resource "ibm_database" "postgresql_db" {
count = var.existing_postgres_instance == "" ? 1 : 0
resource_group_id = module.resource_group.resource_group_id
name = "pgsql-${local.prefix}-instance"
service = "databases-for-postgresql"
plan = "standard"
location = var.ibmcloud_region
adminpassword = random_string.admin_password.result
group {
group_id = "member"
memory {
allocation_mb = 1024
}
disk {
allocation_mb = 5120
}
}
tags = local.tags
}
resource "ibm_resource_key" "postgres_connection" {
name = "${local.prefix}-credentials"
resource_instance_id = local.database_id
}
resource "ibm_code_engine_project" "code_engine_project_instance" {
name = "${local.prefix}-ce-project"
resource_group_id = module.resource_group.resource_group_id
}
resource "ibm_code_engine_config_map" "app_configmap" {
project_id = ibm_code_engine_project.code_engine_project_instance.id
name = "${local.prefix}-app-configmap"
data = {
PORT = "8080"
DB = "sql"
BASKET = "ball"
}
}
resource "ibm_code_engine_secret" "db_credentials" {
project_id = ibm_code_engine_project.code_engine_project_instance.id
name = "${local.prefix}-database-connection"
format = "generic"
data = {
CONN = "postgres://${local.database_user}:${local.database_password}@${local.database_host}:${local.database_port}/ibmclouddb?sslmode=require"
TOKEN = random_string.rb_master_token.result
}
}
resource "ibm_code_engine_app" "request_baskets" {
project_id = ibm_code_engine_project.code_engine_project_instance.project_id
name = "${local.prefix}-rb-app"
image_reference = "darklynx/request-baskets"
scale_min_instances = 1
scale_max_instances = 1
run_env_variables {
type = "secret_full_reference"
reference = "${local.prefix}-database-connection"
}
run_env_variables {
type = "config_map_full_reference"
reference = "${local.prefix}-app-configmap"
}
}