-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
302 lines (250 loc) · 9.79 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
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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = var.aws_region
# profile = "mck-sandbox"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
token = var.aws_session_token
}
module "instance_key_pair" {
source = "github.com/TH-Logistic/key_pair"
key_pair_name = var.key_pair_name
}
module "vpc" {
source = "github.com/TH-Logistic/vpc"
}
module "internet_gateway" {
source = "github.com/TH-Logistic/gateway"
vpc_id = module.vpc.vpc_id
}
module "instance_mongo" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-mongo"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.0.0/24"
user_data = templatefile("./scripts/instance-user-data/mongo-db.tftpl", {
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
})
}
# module "instance_rds" {
# source = "github.com/thinhlh/terraform-rds"
# vpc_id = module.vpc.vpc_id
# subnet_cidr_1 = "10.0.10.0/24"
# subnet_cidr_2 = "10.0.20.0/24"
# internet_gateway_id = module.internet_gateway.internet_gateway_id
# engine = "postgres"
# rds_db_name = var.rds_db_name
# rds_username = var.rds_username
# rds_password = var.rds_password
# allocated_storage = 10
# }
module "instance_rds" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-rds"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.10.0/24"
user_data = templatefile("./scripts/instance-user-data/postgres-db.tftpl", {
postgres_db = var.rds_db_name
postgres_user = var.rds_username
postgres_password = rds_password
})
}
module "instance_auth" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-auth"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.30.0/24"
user_data = templatefile("./scripts/instance-user-data/auth-service.tftpl", {
algorithm = "HS256"
secret_key = var.app_secret
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
})
}
module "instance_product" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-product"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.40.0/24"
user_data = templatefile("./scripts/instance-user-data/product-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_transportation" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-transportation"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.50.0/24"
user_data = templatefile("./scripts/instance-user-data/transportation-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
google_map_api_key = "AIzaSyDEokOCthVrnmMPiI_fLEZKQtV1SjFvjxQ"
})
}
module "instance_organization" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-organization"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.60.0/24"
user_data = templatefile("./scripts/instance-user-data/organization-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_route" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-route"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.70.0/24"
user_data = templatefile("./scripts/instance-user-data/route-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
google_map_api_key = "AIzaSyDEokOCthVrnmMPiI_fLEZKQtV1SjFvjxQ"
})
}
module "instance_healthcheck" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-healthcheck"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.80.0/24"
user_data = templatefile("./scripts/instance-user-data/healthcheck-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_job" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-job"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.90.0/24"
user_data = templatefile("./scripts/instance-user-data/job-service.tftpl", {
postgres_host = module.instance_rds.public_ip
postgres_port = 5432
postgres_db = var.rds_db_name
postgres_user = var.rds_username
postgres_password = var.rds_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_billing" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-billing"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.100.0/24"
user_data = templatefile("./scripts/instance-user-data/billing-service.tftpl", {
postgres_host = module.instance_rds.public_ip
postgres_port = 5432
postgres_db = var.rds_db_name
postgres_user = var.rds_username
postgres_password = var.rds_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_user" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-user"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.110.0/24"
user_data = templatefile("./scripts/instance-user-data/user-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
auth_url = "${module.instance_auth.public_ip}:8000"
root_user = var.root_password
root_password = var.root_user
})
}
module "instance_mail" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-mail"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.130.0/24"
user_data = templatefile("./scripts/instance-user-data/mail-service.tftpl", {
mongo_host = module.instance_mongo.public_ip
mongo_port = 27017
mongo_db_name = var.mongo_db_name
mongo_username = var.mongo_username
mongo_password = var.mongo_password
domain_url = module.instance_gateway.public_ip
})
}
module "instance_gateway" {
source = "github.com/TH-Logistic/ec2"
key_pair_name = module.instance_key_pair.key_pair_name
instance_name = "th-gateway"
internet_gateway_id = module.internet_gateway.internet_gateway_id
vpc_id = module.vpc.vpc_id
subnet_cidr = "10.0.140.0/24"
user_data = templatefile("./scripts/instance-user-data/gateway.tftpl", {
product_host = module.instance_product.public_ip
transportation_host = module.instance_transportation.public_ip
garage_host = module.instance_transportation.public_ip
organization_host = module.instance_organization.public_ip
route_host = module.instance_route.public_ip
location_host = module.instance_route.public_ip
healthcheck_host = module.instance_healthcheck.public_ip
job_host = module.instance_job.public_ip
billing_host = module.instance_billing.public_ip
mail_host = module.instance_mail.public_ip
auth_host = module.instance_auth.public_ip
user_host = module.instance_user.public_ip
})
}