Skip to content

Commit c84146c

Browse files
committed
feat: add missing resources for fully automatic deploy
1 parent 166d389 commit c84146c

File tree

16 files changed

+312
-134
lines changed

16 files changed

+312
-134
lines changed

.terraform.lock.hcl

Lines changed: 31 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_gateway.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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_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+
34+
resource "aws_apigatewayv2_route" "client_identification" {
35+
api_id = local.api_id
36+
route_key = "POST /identification/clients/identification"
37+
38+
// Identification Lambda integration
39+
target = "integrations/${aws_apigatewayv2_integration.lambda_identification_nationalid.id}"
40+
}
41+
42+
resource "aws_apigatewayv2_route" "order_checkout_and_listing" {
43+
api_id = local.api_id
44+
route_key = "ANY /order/orders" // due to Servlet Filter urlPatterns not supporting specific HTTP methods
45+
46+
// Client Lambda Authorizer authorization
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+
// Client Lambda Authorizer authorization
57+
target = "integrations/${local.proxy_to_alb_id}"
58+
59+
}

cloudwatch.tf

Lines changed: 19 additions & 0 deletions
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/payment.json

Lines changed: 16 additions & 0 deletions
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

Lines changed: 6 additions & 2 deletions
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": {

datasources.tf

Lines changed: 0 additions & 54 deletions
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

Lines changed: 0 additions & 4 deletions
This file was deleted.

lambda.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# module "lambda_identification_nationalid" {
2+
# source = "https://github.com/soat-tech-challenge/lambda-identification-nationalid/releases/download/phase-4/artifact-phase-5.zip"
3+
# }
4+
5+
# module "lambda_authorizer_client" {
6+
# source = "https://github.com/soat-tech-challenge/lambda-authorizer-client/releases/download/phase-4/artifact-phase-5.zip"
7+
# }
8+
9+
# data "archive_file" "lambda1" {
10+
# type = "zip"
11+
# source_file = "${path.module}/init.tpl"
12+
# output_path = "${path.module}/files/init.zip"
13+
# }
14+
15+
# resource "aws_lambda_function" "identification_nationalid" {
16+
# filename = terraform_data.download_archive_lambda1.output
17+
# function_name = "SOAT_TC_Lambda_Identification_NationalID"
18+
# description = "Generates Client JWT using National ID"
19+
# role = data.aws_iam_role.lab_role.arn
20+
# handler = "index.handler"
21+
22+
# source_code_hash = filebase64sha256(terraform_data.download_archive_lambda1.output)
23+
24+
# runtime = "nodejs20.x"
25+
26+
# environment {
27+
# variables = {
28+
# BACKEND_URL = local.alb_url
29+
# JWT_PRIVATE_KEY = var.client_jwt_private_key
30+
# }
31+
# }
32+
33+
# vpc_config {
34+
# subnet_ids = local.private_subnets_ids
35+
# security_group_ids = [local.default_sg_id]
36+
# }
37+
38+
# logging_config {
39+
# log_format = "Text"
40+
# log_group = aws_cloudwatch_log_group.lambda_identification_nationalid.name
41+
# }
42+
# }
43+
44+
# resource "aws_lambda_function" "authorizer_client" {
45+
# filename = terraform_data.download_archive_lambda2.output
46+
# function_name = "SOAT_TC_Lambda_Authorizer_Client"
47+
# description = "Authorizer Lambda for Client requests"
48+
# role = data.aws_iam_role.lab_role.arn
49+
# handler = "index.handler"
50+
51+
# source_code_hash = filebase64sha256(terraform_data.download_archive_lambda2.output)
52+
53+
# runtime = "nodejs20.x"
54+
55+
# environment {
56+
# variables = {
57+
# BACKEND_URL = local.alb_url
58+
# JWT_PRIVATE_KEY = var.client_jwt_private_key
59+
# }
60+
# }
61+
62+
# logging_config {
63+
# log_format = "Text"
64+
# log_group = aws_cloudwatch_log_group.lambda_authorizer_client.name
65+
# }
66+
# }

lambda_variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable "client_jwt_private_key" {
2+
description = "RSA256 Private Key used by Identification National ID Lambda for signing JWT"
3+
default = "MIIEowIBAAKCAQEAqStd8n4SGNM0eZhV/hzU+urHA5/IMZPoP9YQ9ZcLKWiX33nI6bSuZMCrLZcJExf63xS+uxDpGxM8Mnk2zOdl+lPwANXLzP1us5P1PyA3YPycW9J7C5YTQW0GiEL3M93ZX7vMJiVoBYblP3JPlYnoYlBORuc0JPk33KtfEZP+78qXpPHM8imYrJLe8ceiDLLFDU/nh5KC2dWAy3ci1ahoJ1Q9ELhp3IZLvOTX57H/T2VKOYOya5+ST41h+JjzI+qGTVnLcKaW+k25YLlVnkSspvdx98+yQDi7kbOTS6yRZHUPD6wPk/nUozpD0nZKccoH4W+zMwmQVtsAA6JCA9gfGwIDAQABAoIBAEU/KbkpzumXhsrhRw36Klo9gVJj9NQKec6rpwyIk/qSxFwnY0z690nprgg+42mL7tajDMHRFcJN+N2mTX7Jl65E7qDA4ygZc1eR0JlS7ChIrw5NFa3z9BTbdomPc9Yo0SKFYncY58AfbDaw6Y/KQDQCMFCIsokR9MJ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