Skip to content

Commit

Permalink
Merge pull request #27 from clouddrove/yaac1
Browse files Browse the repository at this point in the history
add with_target_group variable
  • Loading branch information
d4kverma committed Aug 11, 2022
2 parents 94bc8fd + 1a411fe commit a9b501f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion _example/alb/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module "ec2" {
instance_profile_enabled = true
iam_instance_profile = module.iam-role.name


ebs_optimized = false
ebs_volume_enabled = true
ebs_volume_type = "gp2"
Expand All @@ -137,6 +137,7 @@ module "alb" {
security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids]
subnets = module.public_subnets.public_subnet_id
enable_deletion_protection = false
with_target_group = true

target_id = module.ec2.instance_id
vpc_id = module.vpc.vpc_id
Expand Down
4 changes: 3 additions & 1 deletion _example/clb/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ module "ec2" {
instance_profile_enabled = true
iam_instance_profile = module.iam-role.name


ebs_optimized = false
ebs_volume_enabled = true
ebs_volume_type = "gp2"
Expand All @@ -134,6 +134,8 @@ module "clb" {
target_id = module.ec2.instance_id
security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids]
subnets = module.public_subnets.public_subnet_id
with_target_group = true


listeners = [
{
Expand Down
1 change: 1 addition & 0 deletions _example/nlb/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module "nlb" {
instance_count = module.ec2.instance_count
subnets = module.public_subnets.public_subnet_id
enable_deletion_protection = false
with_target_group = true

target_id = module.ec2.instance_id
vpc_id = module.vpc.vpc_id
Expand Down
14 changes: 7 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ resource "aws_lb" "main" {
# Module : LOAD BALANCER LISTENER HTTPS
# Description : Provides a Load Balancer Listener resource.
resource "aws_lb_listener" "https" {
count = var.enable == true && var.https_enabled == true && var.load_balancer_type == "application" ? 1 : 0
count = var.enable == true && var.with_target_group && var.https_enabled == true && var.load_balancer_type == "application" ? 1 : 0

load_balancer_arn = element(aws_lb.main.*.arn, count.index)
port = var.https_port
Expand All @@ -85,7 +85,7 @@ resource "aws_lb_listener" "https" {
# Module : LOAD BALANCER LISTENER HTTP
# Description : Provides a Load Balancer Listener resource.
resource "aws_lb_listener" "http" {
count = var.enable == true && var.http_enabled == true && var.load_balancer_type == "application" ? 1 : 0
count = var.enable == true && var.with_target_group && var.http_enabled == true && var.load_balancer_type == "application" ? 1 : 0

load_balancer_arn = element(aws_lb.main.*.arn, count.index)
port = var.http_port
Expand All @@ -104,7 +104,7 @@ resource "aws_lb_listener" "http" {
# Module : LOAD BALANCER LISTENER HTTPS
# Description : Provides a Load Balancer Listener resource.
resource "aws_lb_listener" "nhttps" {
count = var.enable == true && var.https_enabled == true && var.load_balancer_type == "network" ? length(var.https_listeners) : 0
count = var.enable == true && var.with_target_group && var.https_enabled == true && var.load_balancer_type == "network" ? length(var.https_listeners) : 0

load_balancer_arn = element(aws_lb.main.*.arn, count.index)
port = var.https_listeners[count.index]["port"]
Expand All @@ -120,7 +120,7 @@ resource "aws_lb_listener" "nhttps" {
# Module : LOAD BALANCER LISTENER HTTP
# Description : Provides a Load Balancer Listener resource.
resource "aws_lb_listener" "nhttp" {
count = var.enable == true && var.load_balancer_type == "network" ? length(var.http_tcp_listeners) : 0
count = var.enable == true && var.with_target_group && var.load_balancer_type == "network" ? length(var.http_tcp_listeners) : 0

load_balancer_arn = element(aws_lb.main.*.arn, 0)
port = var.http_tcp_listeners[count.index]["port"]
Expand All @@ -134,7 +134,7 @@ resource "aws_lb_listener" "nhttp" {
# Module : LOAD BALANCER TARGET GROUP
# Description : Provides a Target Group resource for use with Load Balancer resources.
resource "aws_lb_target_group" "main" {
count = var.enable ? length(var.target_groups) : 0
count = var.enable && var.with_target_group ? length(var.target_groups) : 0
name = format("%s-%s", module.labels.id, count.index)
port = lookup(var.target_groups[count.index], "backend_port", null)
protocol = lookup(var.target_groups[count.index], "backend_protocol", null) != null ? upper(lookup(var.target_groups[count.index], "backend_protocol")) : null
Expand Down Expand Up @@ -177,15 +177,15 @@ resource "aws_lb_target_group" "main" {
# Description : Provides the ability to register instances and containers with an
# Application Load Balancer (ALB) or Network Load Balancer (NLB) target group.
resource "aws_lb_target_group_attachment" "attachment" {
count = var.enable && var.load_balancer_type == "application" && var.target_type == "" ? var.instance_count : 0
count = var.enable && var.with_target_group && var.load_balancer_type == "application" && var.target_type == "" ? var.instance_count : 0

target_group_arn = element(aws_lb_target_group.main.*.arn, count.index)
target_id = element(var.target_id, count.index)
port = var.target_group_port
}

resource "aws_lb_target_group_attachment" "nattachment" {
count = var.enable && var.load_balancer_type == "network" ? length(var.https_listeners) : 0
count = var.enable && var.with_target_group && var.load_balancer_type == "network" ? length(var.https_listeners) : 0

target_group_arn = element(aws_lb_target_group.main.*.arn, count.index)
target_id = element(var.target_id, 0)
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,8 @@ variable "https_listener_rules" {
default = []
}

variable "with_target_group" {
type = bool
default = true
description = "Create LoadBlancer without target group"
}

0 comments on commit a9b501f

Please sign in to comment.