Skip to content

Commit

Permalink
Merge pull request #26 from soat-fiap/config_noauth_webhook
Browse files Browse the repository at this point in the history
feat: add payment webhook integration
  • Loading branch information
italopessoa authored Nov 28, 2024
2 parents d483191 + 401cf3c commit 0b91c75
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
terraform_version: 1.9.4

- name: Terraform Init
run: terraform init -upgrade
Expand Down
19 changes: 0 additions & 19 deletions .terraform.lock.hcl

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

20 changes: 10 additions & 10 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
# }
# }

data "aws_lb" "eks_payment_elb" {
tags = {
"kubernetes.io/service-name" = "fiap-payment/api-internal"
}
}
# data "aws_lb" "eks_payment_elb" {
# tags = {
# "kubernetes.io/service-name" = "fiap-payment/api-internal"
# }
# }

data "aws_lb" "eks_kitchen_elb" {
tags = {
"kubernetes.io/service-name" = "fiap-production/api-internal"
}
}
# data "aws_lb" "eks_kitchen_elb" {
# tags = {
# "kubernetes.io/service-name" = "fiap-production/api-internal"
# }
# }

data "aws_lb" "load_balancers" {
for_each = var.services
Expand Down
54 changes: 51 additions & 3 deletions modules/rest_api/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ resource "aws_api_gateway_integration" "integrations" {
"integration.request.path.proxy" = "method.request.path.proxy"
"integration.request.header.accessToken" = "context.authorizer.accessToken"
}

}

resource "aws_api_gateway_authorizer" "cpf_auth" {
Expand All @@ -73,12 +72,18 @@ resource "aws_api_gateway_deployment" "dev" {
depends_on = [aws_api_gateway_integration.integrations]
rest_api_id = aws_api_gateway_rest_api.api_gtw.id
# stage_name = "dev"
description = sha1(jsonencode(aws_api_gateway_rest_api.api_gtw.body))
description = sha1(jsonencode([
aws_api_gateway_rest_api.api_gtw.body,
aws_api_gateway_resource.payment_webhook_proxy
]))
lifecycle {
create_before_destroy = true
}
triggers = {
redeployment = sha1(jsonencode(aws_api_gateway_rest_api.api_gtw.body))
redeployment = sha1(jsonencode([
aws_api_gateway_rest_api.api_gtw.body,
aws_api_gateway_resource.payment_webhook_proxy
]))
}
}

Expand Down Expand Up @@ -175,3 +180,46 @@ resource "aws_api_gateway_integration_response" "cors_integration_response" {
"method.response.header.Access-Control-Allow-Origin" = "'*'"
}
}

######### NO AUTH WEBHOOK ######

resource "aws_api_gateway_resource" "payment_webhook_resource" {
depends_on = [
aws_api_gateway_resource.resource["payment"],
]
rest_api_id = aws_api_gateway_rest_api.api_gtw.id
parent_id = aws_api_gateway_resource.resource["payment"].id
path_part = "webhook"
}

resource "aws_api_gateway_resource" "payment_webhook_proxy" {
rest_api_id = aws_api_gateway_rest_api.api_gtw.id
parent_id = aws_api_gateway_resource.payment_webhook_resource.id
path_part = "{proxy+}"
}

resource "aws_api_gateway_method" "payment_webhook_proxy_method" {
rest_api_id = aws_api_gateway_rest_api.api_gtw.id
resource_id = aws_api_gateway_resource.payment_webhook_proxy.id
http_method = "POST"
authorization = "NONE"
request_parameters = {
"method.request.path.proxy" = true
}
}

resource "aws_api_gateway_integration" "payment_webhook_integrations" {
rest_api_id = aws_api_gateway_rest_api.api_gtw.id
resource_id = aws_api_gateway_resource.payment_webhook_proxy.id
http_method = aws_api_gateway_method.payment_webhook_proxy_method.http_method
type = "HTTP_PROXY"
uri = "http://${var.elb_map["payment"].dns_name}/api/notifications/{proxy}"
integration_http_method = "POST"
connection_type = "VPC_LINK"
connection_id = aws_api_gateway_vpc_link.vpc_link["payment"].id

timeout_milliseconds = 29000
request_parameters = {
"integration.request.path.proxy" = "method.request.path.proxy"
}
}
6 changes: 1 addition & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "jwt_issuer" {
}

variable "services" {
type = map(object({
type = map(object({
namespace = string
auth = bool
}))
Expand All @@ -62,9 +62,5 @@ variable "services" {
namespace = "fiap-orders"
auth = true
}
# "log" = {
# namespace = "fiap-log"
# auth = false
# }
}
}

0 comments on commit 0b91c75

Please sign in to comment.