Skip to content

Commit 166d389

Browse files
authored
fix: port and other service modules values (#10)
2 parents 4004ce5 + 875232b commit 166d389

File tree

8 files changed

+192
-26
lines changed

8 files changed

+192
-26
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "SOAT-TC_ECS_${id}_SVC_Main_Container",
4+
"image": "registry.hub.docker.com/g0tn/soat-tech-challenge-service-${id}",
5+
"cpu": 512,
6+
"memory": 1024,
7+
"essential": true,
8+
"portMappings": [
9+
{
10+
"containerPort": 8001,
11+
"hostPort": 8001
12+
}
13+
],
14+
"environment": [
15+
{
16+
"name": "AWS_ACCESS_KEY",
17+
"value": "${aws_access_key}"
18+
},
19+
{
20+
"name": "AWS_SECRET_KEY",
21+
"value": "${aws_secret_key}"
22+
},
23+
{
24+
"name": "AWS_SESSION_TOKEN",
25+
"value": "${aws_session_token}"
26+
},
27+
{
28+
"name": "AWS_DYNAMODB_ENDPOINT",
29+
"value": "${aws_dynamodb_endpoint}"
30+
},
31+
{
32+
"name": "JWT_PUBLIC_KEY",
33+
"value": "${client_jwt_pub_key}"
34+
}
35+
],
36+
"logConfiguration": {
37+
"logDriver": "awslogs",
38+
"options": {
39+
"awslogs-create-group": "true",
40+
"awslogs-group": "/aws/ecs/SOAT-TC_ECS_${id}_Service_Logs",
41+
"awslogs-region": "${aws_region}",
42+
"awslogs-stream-prefix": "${id}-svc"
43+
}
44+
}
45+
}
46+
]

container_definitions/order.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"name": "API_URL_IDENTIFICATION",
37-
"value": "${lb_dns_name}"
37+
"value": "${api_url_identification}"
3838
}
3939
],
4040
"logConfiguration": {

container_definitions/payment.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"essential": true,
88
"portMappings": [
99
{
10-
"containerPort": 8002,
11-
"hostPort": 8002
10+
"containerPort": 8003,
11+
"hostPort": 8003
1212
}
1313
],
1414
"environment": [
@@ -33,8 +33,12 @@
3333
"value": "${client_jwt_pub_key}"
3434
},
3535
{
36-
"name": "API_URL_IDENTIFICATION",
37-
"value": "${lb_dns_name}"
36+
"name": "API_URL_ORDER",
37+
"value": "${api_url_order}"
38+
},
39+
{
40+
"name": "API_URL_PRODUCTION",
41+
"value": "${api_url_production}"
3842
}
3943
],
4044
"logConfiguration": {

container_definitions/production.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "SOAT-TC_ECS_${id}_SVC_Main_Container",
4+
"image": "registry.hub.docker.com/g0tn/soat-tech-challenge-service-${id}",
5+
"cpu": 512,
6+
"memory": 1024,
7+
"essential": true,
8+
"portMappings": [
9+
{
10+
"containerPort": 8004,
11+
"hostPort": 8004
12+
}
13+
],
14+
"environment": [
15+
{
16+
"name": "AWS_ACCESS_KEY",
17+
"value": "${aws_access_key}"
18+
},
19+
{
20+
"name": "AWS_SECRET_KEY",
21+
"value": "${aws_secret_key}"
22+
},
23+
{
24+
"name": "AWS_SESSION_TOKEN",
25+
"value": "${aws_session_token}"
26+
},
27+
{
28+
"name": "AWS_DYNAMODB_ENDPOINT",
29+
"value": "${aws_dynamodb_endpoint}"
30+
},
31+
{
32+
"name": "JWT_PUBLIC_KEY",
33+
"value": "${client_jwt_pub_key}"
34+
}
35+
],
36+
"logConfiguration": {
37+
"logDriver": "awslogs",
38+
"options": {
39+
"awslogs-create-group": "true",
40+
"awslogs-group": "/aws/ecs/SOAT-TC_ECS_${id}_Service_Logs",
41+
"awslogs-region": "${aws_region}",
42+
"awslogs-stream-prefix": "${id}-svc"
43+
}
44+
}
45+
}
46+
]

database_variables.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ variable "order_svc_db_name" {
1515
default = "postgres"
1616
}
1717

18-
variable "order_svc_db_port" {
19-
description = "Order Service RDS Database instance port"
20-
type = number
21-
default = 5432
22-
}
23-
2418
// ---
2519

2620
variable "payment_svc_db_username" {
@@ -39,9 +33,3 @@ variable "payment_svc_db_name" {
3933
type = string
4034
default = "postgres"
4135
}
42-
43-
variable "payment_svc_db_port" {
44-
description = "Payment Service RDS Database instance port"
45-
type = number
46-
default = 5432
47-
}

datasources.tf

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ data "tfe_outputs" "database" {
1212
organization = "soat-tech-challenge"
1313
workspace = "database-staging"
1414
}
15+
data "template_file" "identification_svc_container_definition" {
16+
template = file("./container_definitions/identification.json")
17+
vars = {
18+
id = "identification"
19+
aws_access_key = var.aws_access_key
20+
aws_secret_key = var.aws_secret_key
21+
aws_session_token = var.aws_session_token
22+
aws_dynamodb_endpoint = "dynamodb.${var.aws_region}.amazonaws.com"
23+
client_jwt_pub_key = var.client_jwt_public_key
24+
aws_region = var.aws_region
25+
}
26+
}
27+
1528

1629
data "template_file" "order_svc_container_definition" {
1730
template = file("./container_definitions/order.json")
1831
vars = {
19-
id = "order"
20-
db_username = var.order_svc_db_username
21-
db_password = var.order_svc_db_password
22-
db_name = var.order_svc_db_name
23-
db_host = data.tfe_outputs.database.values.order_svc_db.endpoint
24-
client_jwt_pub_key = var.client_jwt_public_key
25-
lb_dns_name = data.tfe_outputs.network.values.lb_lb.dns_name
26-
aws_region = var.aws_region
32+
id = "order"
33+
db_username = var.order_svc_db_username
34+
db_password = var.order_svc_db_password
35+
db_name = var.order_svc_db_name
36+
db_host = data.tfe_outputs.database.values.order_svc_db.endpoint
37+
client_jwt_pub_key = var.client_jwt_public_key
38+
api_url_identification = "${data.tfe_outputs.network.values.lb_lb.dns_name}/identification"
39+
aws_region = var.aws_region
2740
}
2841
}
2942

@@ -36,7 +49,21 @@ data "template_file" "payment_svc_container_definition" {
3649
db_name = var.payment_svc_db_name
3750
db_host = data.tfe_outputs.database.values.payment_svc_db.endpoint
3851
client_jwt_pub_key = var.client_jwt_public_key
39-
lb_dns_name = data.tfe_outputs.network.values.lb_lb.dns_name
52+
api_url_order = "${data.tfe_outputs.network.values.lb_lb.dns_name}/order"
53+
api_url_production = "${data.tfe_outputs.network.values.lb_lb.dns_name}/production"
4054
aws_region = var.aws_region
4155
}
4256
}
57+
58+
data "template_file" "production_svc_container_definition" {
59+
template = file("./container_definitions/production.json")
60+
vars = {
61+
id = "production"
62+
aws_access_key = var.aws_access_key
63+
aws_secret_key = var.aws_secret_key
64+
aws_session_token = var.aws_session_token
65+
aws_dynamodb_endpoint = "dynamodb.${var.aws_region}.amazonaws.com"
66+
client_jwt_pub_key = var.client_jwt_public_key
67+
aws_region = var.aws_region
68+
}
69+
}

main.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
module "identification" {
2+
source = "./modules/service"
3+
id = "identification"
4+
name = "Identification"
5+
6+
task_role_arn = data.aws_iam_role.lab_role.arn
7+
execution_role_arn = data.aws_iam_role.lab_role.arn
8+
container_definitions = data.template_file.identification_svc_container_definition.rendered
9+
ecs_cluster_id = aws_ecs_cluster.main.id
10+
11+
subnet_ids = data.tfe_outputs.network.values.vpc_public_subnets[*].id
12+
security_groups_ids = [data.tfe_outputs.network.values.vpc_vpc.default_security_group_id]
13+
14+
lb_container_port = 8001
15+
lb_target_group_arn = data.tfe_outputs.network.values.lb_tgs.ecs_identification_svc_tg.arn
16+
}
117
module "order" {
218
source = "./modules/service"
319
id = "order"
@@ -14,3 +30,37 @@ module "order" {
1430
lb_container_port = 8002
1531
lb_target_group_arn = data.tfe_outputs.network.values.lb_tgs.ecs_order_svc_tg.arn
1632
}
33+
34+
module "payment" {
35+
source = "./modules/service"
36+
id = "payment"
37+
name = "Payment"
38+
39+
task_role_arn = data.aws_iam_role.lab_role.arn
40+
execution_role_arn = data.aws_iam_role.lab_role.arn
41+
container_definitions = data.template_file.payment_svc_container_definition.rendered
42+
ecs_cluster_id = aws_ecs_cluster.main.id
43+
44+
subnet_ids = data.tfe_outputs.network.values.vpc_public_subnets[*].id
45+
security_groups_ids = [data.tfe_outputs.network.values.vpc_vpc.default_security_group_id]
46+
47+
lb_container_port = 8003
48+
lb_target_group_arn = data.tfe_outputs.network.values.lb_tgs.ecs_payment_svc_tg.arn
49+
}
50+
51+
module "production" {
52+
source = "./modules/service"
53+
id = "production"
54+
name = "Production"
55+
56+
task_role_arn = data.aws_iam_role.lab_role.arn
57+
execution_role_arn = data.aws_iam_role.lab_role.arn
58+
container_definitions = data.template_file.production_svc_container_definition.rendered
59+
ecs_cluster_id = aws_ecs_cluster.main.id
60+
61+
subnet_ids = data.tfe_outputs.network.values.vpc_public_subnets[*].id
62+
security_groups_ids = [data.tfe_outputs.network.values.vpc_vpc.default_security_group_id]
63+
64+
lb_container_port = 8004
65+
lb_target_group_arn = data.tfe_outputs.network.values.lb_tgs.ecs_production_svc_tg.arn
66+
}

providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ terraform {
1919
source = "hashicorp/tfe"
2020
version = "~> 0.51.1"
2121
}
22+
23+
template = {
24+
source = "hashicorp/template"
25+
version = "~> 2.2.0"
26+
}
2227
}
2328
}
2429

0 commit comments

Comments
 (0)