Skip to content

Commit 42839b2

Browse files
authored
Feat/lambda sqs (#11)
2 parents 166d389 + 59ae8bd commit 42839b2

20 files changed

+362
-137
lines changed

.terraform.lock.hcl

+48-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.tflint.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ plugin "terraform" {
55

66
plugin "aws" {
77
enabled = true
8-
version = "0.27.0"
8+
version = "0.30.0"
99
source = "github.com/terraform-linters/tflint-ruleset-aws"
1010
}

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
# terraform-computing
2+
23
[![Terraform Apply](https://github.com/soat-tech-challenge/terraform-computing/actions/workflows/main.yml/badge.svg)](https://github.com/soat-tech-challenge/terraform-computing/actions/workflows/main.yml)
34

45
Part of a group course project of a self service and kitchen management system for a fictional fast food restaurant.
56

67
Currently responsible for managing computing-related resources of the project.
8+
9+
### Service
10+
11+
#### ECS Exec
12+
13+
Requires: AWS CLI, Session Manager plugin
14+
15+
Enter ECS task container shell using ECS Exec:
16+
17+
```
18+
aws ecs execute-command \
19+
--region us-east-1 \
20+
--cluster SOAT_Tech_Challenge_ECS_Cluster \
21+
--task task-id \
22+
--container SOAT-TC_ECS_<service>_SVC_Main_Container \
23+
--interactive \
24+
--command "/usr/bin/sh"
25+
```
26+
27+
Read more: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-enabling-and-using

api_gateway.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
locals {
2+
api_id = data.tfe_outputs.network.values.api_gw_gateway_api.id
3+
proxy_to_alb_id = data.tfe_outputs.network.values.api_gw_integration_proxy_to_alb.id
4+
}
5+
6+
// ----- Authorizers -----
7+
8+
resource "aws_apigatewayv2_authorizer" "lambda_authorizer_client" {
9+
api_id = local.api_id
10+
authorizer_type = "REQUEST"
11+
authorizer_uri = aws_lambda_function.authorizer_client.invoke_arn
12+
identity_sources = ["$request.header.Authorization"]
13+
name = "SOAT-TC_API_Gateway_Authorizer__Lambda_Authorizer_Client"
14+
15+
authorizer_payload_format_version = "2.0"
16+
enable_simple_responses = true
17+
}
18+
19+
// ----- Integrations -----
20+
21+
resource "aws_apigatewayv2_integration" "lambda_identification_nationalid" {
22+
api_id = local.api_id
23+
integration_type = "AWS_PROXY"
24+
25+
description = "Intercept identification request for token generation flow"
26+
integration_method = "POST"
27+
integration_uri = aws_lambda_function.identification_nationalid.invoke_arn
28+
29+
payload_format_version = "2.0"
30+
}
31+
32+
// ----- Routes -----
33+
// Routes should be declared on terraform-network whenever possible. The routes below
34+
// depend on terraform-computing resources, they are declared here to avoid cyclic dependencies.
35+
36+
resource "aws_apigatewayv2_route" "client_identification" {
37+
api_id = local.api_id
38+
route_key = "POST /identification/clients/identification"
39+
40+
target = "integrations/${aws_apigatewayv2_integration.lambda_identification_nationalid.id}"
41+
}
42+
43+
resource "aws_apigatewayv2_route" "order_checkout_and_listing" {
44+
api_id = local.api_id
45+
route_key = "ANY /order/orders" // due to Servlet Filter urlPatterns not supporting specific HTTP methods
46+
47+
authorizer_id = aws_apigatewayv2_authorizer.lambda_authorizer_client.id
48+
authorization_type = "CUSTOM"
49+
target = "integrations/${local.proxy_to_alb_id}"
50+
}
51+
52+
resource "aws_apigatewayv2_route" "order_confirmation" {
53+
api_id = local.api_id
54+
route_key = "POST /payment/payments/initialize"
55+
56+
authorizer_id = aws_apigatewayv2_authorizer.lambda_authorizer_client.id
57+
authorization_type = "CUSTOM"
58+
target = "integrations/${local.proxy_to_alb_id}"
59+
60+
}

cloudwatch.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#tfsec:ignore:aws-cloudwatch-log-group-customer-key
2+
resource "aws_cloudwatch_log_group" "lambda_authorizer_client" {
3+
name = "/aws/lambda/SOAT-TC_Lambda_Authorizer_Client_Logs"
4+
retention_in_days = 30
5+
6+
tags = {
7+
Name : "SOAT-TC Lambda Authorizer Client Cloudwatch Log Group"
8+
}
9+
}
10+
11+
#tfsec:ignore:aws-cloudwatch-log-group-customer-key
12+
resource "aws_cloudwatch_log_group" "lambda_identification_nationalid" {
13+
name = "/aws/lambda/SOAT-TC_Lambda_Identification_NationalID_Logs"
14+
retention_in_days = 30
15+
16+
tags = {
17+
Name : "SOAT-TC Lambda Identification National ID Cloudwatch Log Group"
18+
}
19+
}

container_definitions/identification.json

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
{
2828
"name": "AWS_DYNAMODB_ENDPOINT",
2929
"value": "${aws_dynamodb_endpoint}"
30-
},
31-
{
32-
"name": "JWT_PUBLIC_KEY",
33-
"value": "${client_jwt_pub_key}"
3430
}
3531
],
3632
"logConfiguration": {

container_definitions/payment.json

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
{
4040
"name": "API_URL_PRODUCTION",
4141
"value": "${api_url_production}"
42+
},
43+
{
44+
"name": "AWS_ACCESS_KEY",
45+
"value": "${aws_access_key}"
46+
},
47+
{
48+
"name": "AWS_SECRET_KEY",
49+
"value": "${aws_secret_key}"
50+
},
51+
{
52+
"name": "AWS_SESSION_TOKEN",
53+
"value": "${aws_session_token}"
54+
},
55+
{
56+
"name": "AWS_SQS_ENDPOINT",
57+
"value": "${aws_sqs_endpoint}"
4258
}
4359
],
4460
"logConfiguration": {

container_definitions/production.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
}
1313
],
1414
"environment": [
15+
{
16+
"name": "JWT_PUBLIC_KEY",
17+
"value": "${client_jwt_pub_key}"
18+
},
1519
{
1620
"name": "AWS_ACCESS_KEY",
1721
"value": "${aws_access_key}"
@@ -29,8 +33,8 @@
2933
"value": "${aws_dynamodb_endpoint}"
3034
},
3135
{
32-
"name": "JWT_PUBLIC_KEY",
33-
"value": "${client_jwt_pub_key}"
36+
"name": "AWS_SQS_ENDPOINT",
37+
"value": "${aws_sqs_endpoint}"
3438
}
3539
],
3640
"logConfiguration": {

database_variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ variable "order_svc_db_password" {
1212
variable "order_svc_db_name" {
1313
description = "Order Service RDS Database instance name"
1414
type = string
15-
default = "postgres"
15+
default = "order_db"
1616
}
1717

1818
// ---
@@ -31,5 +31,5 @@ variable "payment_svc_db_password" {
3131
variable "payment_svc_db_name" {
3232
description = "Payment Service RDS Database instance name"
3333
type = string
34-
default = "postgres"
34+
default = "payment_db"
3535
}

datasources.tf

-54
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,4 @@ 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-
28-
29-
data "template_file" "order_svc_container_definition" {
30-
template = file("./container_definitions/order.json")
31-
vars = {
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
40-
}
41-
}
4215

43-
data "template_file" "payment_svc_container_definition" {
44-
template = file("./container_definitions/payment.json")
45-
vars = {
46-
id = "payment"
47-
db_username = var.payment_svc_db_username
48-
db_password = var.payment_svc_db_password
49-
db_name = var.payment_svc_db_name
50-
db_host = data.tfe_outputs.database.values.payment_svc_db.endpoint
51-
client_jwt_pub_key = var.client_jwt_public_key
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"
54-
aws_region = var.aws_region
55-
}
56-
}
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-
}

ecs_variables.tf

-4
This file was deleted.

0 commit comments

Comments
 (0)