Skip to content

Commit

Permalink
feature #4 - add application load balancer to exchange rate service
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeniosales committed Oct 16, 2022
1 parent ab69138 commit eb86107
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 8 deletions.
7 changes: 6 additions & 1 deletion terraform/env/dev.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
ENV = "dev"
EXCHANGE_RATE_INTERNAL_URL="http://api.dev.sbf.exchangerate.internal.com"
aws_profile = "dev"
vpc_id = "vpc-0b1ae7a4fa0ec7d9d"
SUB_NET_01 = "subnet-05d245e39491bb3d2"
SUB_NET_02 = "subnet-06761316782230c98"
base_url_internal = "http://exchangerate.internal.dev.sbf.com"
route53_zone_host = "internal.dev.sbf.com"
7 changes: 6 additions & 1 deletion terraform/env/hml.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
ENV = "hml"
EXCHANGE_RATE_INTERNAL_URL="http://api.hml.sbf.exchangerate.internal.com"
aws_profile = "hml"
vpc_id = "vpc-0b1ae7a4fa0ec7d9d"
SUB_NET_01 = "subnet-05d245e39491bb3d2"
SUB_NET_02 = "subnet-06761316782230c98"
base_url_internal = "http://exchangerate.internal.dev.sbf.com"
route53_zone_host = "internal.dev.sbf.com"
7 changes: 6 additions & 1 deletion terraform/env/prd.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
ENV = "prd"
EXCHANGE_RATE_INTERNAL_URL="http://api.sbf.exchangerate.internal.com"
aws_profile = "prd"
vpc_id = "vpc-0b1ae7a4fa0ec7d9d"
SUB_NET_01 = "subnet-05d245e39491bb3d2"
SUB_NET_02 = "subnet-06761316782230c98"
base_url_internal = "http://exchangerate.internal.dev.sbf.com"
route53_zone_host = "internal.dev.sbf.com"
30 changes: 30 additions & 0 deletions terraform/load-balance.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "aws_lb" "lb-sbf-exchangerate" {
name = "sbf-exchangerate-${var.aws_profile}-lb"
internal = true
load_balancer_type = "application"
security_groups = [aws_security_group.lb.id]
subnets = [var.SUB_NET_01, var.SUB_NET_02]

ip_address_type = "ipv4"

tags = {
service = "sbf-exchangerate",
stage = var.aws_profile
}
}

resource "aws_lb_listener" "http-lb-sbf-exchangerate" {
load_balancer_arn = aws_lb.lb-sbf-exchangerate.arn
port = "80"
protocol = "HTTP"

default_action {
type = "fixed-response"

fixed_response {
content_type = "text/plain"
message_body = "The resource can't be found."
status_code = "404"
}
}
}
2 changes: 1 addition & 1 deletion terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ terraform {

provider "aws" {
region = "us-east-1"
}
}
15 changes: 15 additions & 0 deletions terraform/route53.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
resource "aws_route53_record" "record-sbf-exchangerate" {
zone_id = data.aws_route53_zone.selected.zone_id
name = "sbf-exchangerate"
type = "A"

alias {
name = aws_lb.lb-sbf-exchangerate.dns_name
zone_id = aws_lb.lb-sbf-exchangerate.zone_id
evaluate_target_health = true
}
}

output "route53_record" {
value = "${aws_route53_record.record-sbf-exchangerate.name}.${data.aws_route53_zone.selected.name}"
}
24 changes: 24 additions & 0 deletions terraform/security-group.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "aws_security_group" "lb" {
name = "sbf-exchangerate-${var.ENV}-alb-sg"
description = "Allow TLS inbound traffic"
vpc_id = var.vpc_id

ingress {
description = "HTTP from ALL"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

tags = {
Name = "allow_tls"
}
}
4 changes: 2 additions & 2 deletions terraform/ssm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ resource "aws_ssm_parameter" "exchange-rate-api-token-ssm" {
resource "aws_ssm_parameter" "exchange-rate-internal-url-ssm" {
name = "/exchangerate/infra/alb/arn"
type = "String"
value = "${var.EXCHANGE_RATE_INTERNAL_URL}"
value = "${var.base_url_internal}"
overwrite = true
}
}
35 changes: 33 additions & 2 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,40 @@ variable "ENV" {
description = "Environment"
default = null
}
variable "vpc_id" {
type = string
description = "VPC ID"
}

variable "EXCHANGE_RATE_INTERNAL_URL" {
variable "SUB_NET_01" {
type = string
description = "Exchange rate microsservice internal url"
description = "sub net"
default = null
}

variable "SUB_NET_02" {
type = string
description = "sub net"
default = null
}

variable "base_url_internal" {
type = string
description = "base url internal for exchange rate microsservice"
}

variable "aws_profile" {
type = string
description = "AWS Profile"
default = null
}

variable "route53_zone_host" {
type = string
description = "Route53 Zone Host"
}

data "aws_route53_zone" "selected" {
name = var.route53_zone_host
private_zone = true
}

0 comments on commit eb86107

Please sign in to comment.