Skip to content

Commit

Permalink
Feat/initial ecs (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-otn authored Jan 29, 2024
2 parents 0c371af + bdba7d5 commit 4004ce5
Show file tree
Hide file tree
Showing 20 changed files with 394 additions and 169 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
pull_request:
branches:
- main
paths-ignore:
- "**/README.md"
workflow_dispatch:

jobs:
Expand Down
72 changes: 54 additions & 18 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
50 changes: 50 additions & 0 deletions container_definitions/order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "SOAT-TC_ECS_${id}_SVC_Main_Container",
"image": "registry.hub.docker.com/g0tn/soat-tech-challenge-service-${id}",
"cpu": 512,
"memory": 1024,
"essential": true,
"portMappings": [
{
"containerPort": 8002,
"hostPort": 8002
}
],
"environment": [
{
"name": "DB_USERNAME",
"value": "${db_username}"
},
{
"name": "DB_PASSWORD",
"value": "${db_password}"
},
{
"name": "DB_NAME",
"value": "${db_name}"
},
{
"name": "DB_HOST",
"value": "${db_host}"
},
{
"name": "JWT_PUBLIC_KEY",
"value": "${client_jwt_pub_key}"
},
{
"name": "API_URL_IDENTIFICATION",
"value": "${lb_dns_name}"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/aws/ecs/SOAT-TC_ECS_${id}_Service_Logs",
"awslogs-region": "${aws_region}",
"awslogs-stream-prefix": "${id}-svc"
}
}
}
]
50 changes: 50 additions & 0 deletions container_definitions/payment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "SOAT-TC_ECS_${id}_SVC_Main_Container",
"image": "registry.hub.docker.com/g0tn/soat-tech-challenge-service-${id}",
"cpu": 512,
"memory": 1024,
"essential": true,
"portMappings": [
{
"containerPort": 8002,
"hostPort": 8002
}
],
"environment": [
{
"name": "DB_USERNAME",
"value": "${db_username}"
},
{
"name": "DB_PASSWORD",
"value": "${db_password}"
},
{
"name": "DB_NAME",
"value": "${db_name}"
},
{
"name": "DB_HOST",
"value": "${db_host}"
},
{
"name": "JWT_PUBLIC_KEY",
"value": "${client_jwt_pub_key}"
},
{
"name": "API_URL_IDENTIFICATION",
"value": "${lb_dns_name}"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/aws/ecs/SOAT-TC_ECS_${id}_Service_Logs",
"awslogs-region": "${aws_region}",
"awslogs-stream-prefix": "${id}-svc"
}
}
}
]
Empty file.
47 changes: 47 additions & 0 deletions database_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variable "order_svc_db_username" {
description = "Order Service RDS Database instance master username"
type = string
}

variable "order_svc_db_password" {
description = "Order Service RDS Database instance master password"
type = string
sensitive = true
}

variable "order_svc_db_name" {
description = "Order Service RDS Database instance name"
type = string
default = "postgres"
}

variable "order_svc_db_port" {
description = "Order Service RDS Database instance port"
type = number
default = 5432
}

// ---

variable "payment_svc_db_username" {
description = "Payment Service RDS Database instance master username"
type = string
}

variable "payment_svc_db_password" {
description = "Payment Service RDS Database instance master password"
type = string
sensitive = true
}

variable "payment_svc_db_name" {
description = "Payment Service RDS Database instance name"
type = string
default = "postgres"
}

variable "payment_svc_db_port" {
description = "Payment Service RDS Database instance port"
type = number
default = 5432
}
46 changes: 35 additions & 11 deletions datasources.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
data "aws_subnets" "private_subnets" {
filter {
name = "tag:Name"
values = ["soat-tech-challenge-subnet-public*"]
}
# AWS Academy Vocareum AWS Learner Lab
data "aws_iam_role" "lab_role" {
name = "LabRole"
}

data "aws_security_group" "sg_default" {
name = "default"
data "tfe_outputs" "network" {
organization = "soat-tech-challenge"
workspace = "network-staging"
}

data "aws_alb_target_group" "tg_alb" {
name = "soat-alb-target-group"
data "tfe_outputs" "database" {
organization = "soat-tech-challenge"
workspace = "database-staging"
}

data "aws_db_instance" "db_instance" {
db_instance_identifier = "soat-tc-rds-db"
data "template_file" "order_svc_container_definition" {
template = file("./container_definitions/order.json")
vars = {
id = "order"
db_username = var.order_svc_db_username
db_password = var.order_svc_db_password
db_name = var.order_svc_db_name
db_host = data.tfe_outputs.database.values.order_svc_db.endpoint
client_jwt_pub_key = var.client_jwt_public_key
lb_dns_name = data.tfe_outputs.network.values.lb_lb.dns_name
aws_region = var.aws_region
}
}

data "template_file" "payment_svc_container_definition" {
template = file("./container_definitions/payment.json")
vars = {
id = "payment"
db_username = var.payment_svc_db_username
db_password = var.payment_svc_db_password
db_name = var.payment_svc_db_name
db_host = data.tfe_outputs.database.values.payment_svc_db.endpoint
client_jwt_pub_key = var.client_jwt_public_key
lb_dns_name = data.tfe_outputs.network.values.lb_lb.dns_name
aws_region = var.aws_region
}
}
7 changes: 7 additions & 0 deletions ecs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "aws_ecs_cluster" "main" {
name = "SOAT_Tech_Challenge_ECS_Cluster"

tags = {
Name : "SOAT Tech Challenge ECS Cluster"
}
}
4 changes: 4 additions & 0 deletions ecs_variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "client_jwt_public_key" {
default = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqStd8n4SGNM0eZhV/hzU+urHA5/IMZPoP9YQ9ZcLKWiX33nI6bSuZMCrLZcJExf63xS+uxDpGxM8Mnk2zOdl+lPwANXLzP1us5P1PyA3YPycW9J7C5YTQW0GiEL3M93ZX7vMJiVoBYblP3JPlYnoYlBORuc0JPk33KtfEZP+78qXpPHM8imYrJLe8ceiDLLFDU/nh5KC2dWAy3ci1ahoJ1Q9ELhp3IZLvOTX57H/T2VKOYOya5+ST41h+JjzI+qGTVnLcKaW+k25YLlVnkSspvdx98+yQDi7kbOTS6yRZHUPD6wPk/nUozpD0nZKccoH4W+zMwmQVtsAA6JCA9gfGwIDAQAB"
type = string
}
Loading

0 comments on commit 4004ce5

Please sign in to comment.