Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 43 additions & 37 deletions modules/lb-asg/main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
resource "aws_iam_instance_profile" "instance_profile" {
name = "instance-profile"
name = var.instance_profile

role = "instance_role"
role = var.instance_roles
}

resource "aws_security_group" "alb_sg" {
name_prefix = "alb-sg"
resource "aws_security_group" "lb_sg" {
name_prefix = var.lb_security_group

ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = var.from_port
to_port = var.to_port
protocol = var.protocol
cidr_blocks = var.cidr_block
}

egress {
Expand All @@ -23,43 +23,43 @@ resource "aws_security_group" "alb_sg" {

tags = merge(
{
Name = "petclinic-alb-sg",
Name = "${var.name}-lb-sg",
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Application = "pet-clinic"
Application = var.application
},
var.tags
)
}
resource "aws_lb" "petclinic" {
name = "petclinic-alb"
internal = false
load_balancer_type = "application"
name = "${var.name}-lb"
internal = var.internal
load_balancer_type = var.lb_type

subnets = var.subnets
security_groups = [aws_security_group.alb_sg.id]

tags = merge(
{
Name = "petclinic-alb",
Name = "${var.name}-lb",
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Application = "pet-clinic"
Application = var.application
},
var.tags
)
}

resource "aws_security_group" "instance_sg" {
name_prefix = "petclinic-sg"
name_prefix = var.instance_sg

ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = instance_from_port
to_port = instance_to_port
protocol = instance_protocol
cidr_blocks = instance_cidr_block
}

egress {
Expand All @@ -71,38 +71,44 @@ resource "aws_security_group" "instance_sg" {

tags = merge(
{
Name = "petclinic-sg"
Name = "${var.name}-instance-sg"
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Application = "pet-clinic"
Application = var.application
},
var.tags
)
}


resource "aws_lb_target_group" "petclinic" {
name_prefix = "pc-lb"
port = 8080
protocol = "HTTP"
name_prefix = var.target_group_name
port = var.target_group_port
protocol = var.target_group_protocol
vpc_id = var.vpc_id
target_type = "instance"
target_type = var.target_type

health_check {
path = "/"
port = 8080
protocol = "HTTP"
interval = 30
timeout = 5
healthy_threshold = 2
unhealthy_threshold = 2
path = var.health_check_path
port = var.health_check_port
protocol = var.health_check_protocol
interval = var.health_check_interval
timeout = var.health_check_timeout
healthy_threshold = var.health_check_healthy_threshold
unhealthy_threshold = var.health_check_unhealthy_threshold
}

tags = {
Environment = var.environment
Terraform = "true"
}
tags = merge(
{
Name = "${var.name}-lb-target-group"
Environment = var.environment,
Owner = var.owner,
CostCenter = var.cost_center,
Application = var.application
},
var.tags
)
}

resource "aws_lb_listener" "petclinic" {
Expand Down
39 changes: 36 additions & 3 deletions vars/dev/lb-asg.tfvars
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
region = "us-west-2"
owner = "Techiescamp"
environment = "dev"
cost_center = "project-pet-clinic"
# iam_role
instance_profile = "FullAccessProfile"
instance_role = "instance_role"
# lb_sg
lb_security_group = "lb-sg"
lb_from_port = 0
lb_to_port = 65535
lb_protocol = "tcp"
lb_cidr_block = ["0.0.0.0/0"]
internal = false
lb_type = "application"
# insatnce_sg
instance_sg = "petclinic_instance_sg"
instance_from_port = 0
instance_to_port = 65535
instance_protocol = "tcp"
instance_cidr_block = ["0.0.0.0/0"]
# target_group
target_group_name = "pc-lb"
target_group_port = 8080
target_group_protocol = "HTTP"
target_type = "instance"
# health_check
health_check_path = "/"
health_check_port = 8080
health_check_protocol = "HTTP"
health_check_interval = 30
health_check_timeout = 5
health_check_healthy_treshold = 2
health_check_unhealthy_treshold = 2

ami_id = "ami-08076abdd4bdb9b18"
instance_type = "t2.medium"
key_name = "aswin-key"
vpc_id = "vpc-0a5ca4a92c2e10163"
subnets = ["subnet-058a7514ba8adbb07", "subnet-0dbcd1ac168414927", "subnet-032f5077729435858"]

name = "petclinic"
owner = "Techiescamp"
environment = "dev"
cost_center = "project-pet-clinic"
application = "pet-clinic"