Skip to content

Commit a9b501f

Browse files
authored
Merge pull request #27 from clouddrove/yaac1
add with_target_group variable
2 parents 94bc8fd + 1a411fe commit a9b501f

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

_example/alb/example.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module "ec2" {
119119
instance_profile_enabled = true
120120
iam_instance_profile = module.iam-role.name
121121

122-
122+
123123
ebs_optimized = false
124124
ebs_volume_enabled = true
125125
ebs_volume_type = "gp2"
@@ -137,6 +137,7 @@ module "alb" {
137137
security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids]
138138
subnets = module.public_subnets.public_subnet_id
139139
enable_deletion_protection = false
140+
with_target_group = true
140141

141142
target_id = module.ec2.instance_id
142143
vpc_id = module.vpc.vpc_id

_example/clb/example.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module "ec2" {
117117
instance_profile_enabled = true
118118
iam_instance_profile = module.iam-role.name
119119

120-
120+
121121
ebs_optimized = false
122122
ebs_volume_enabled = true
123123
ebs_volume_type = "gp2"
@@ -134,6 +134,8 @@ module "clb" {
134134
target_id = module.ec2.instance_id
135135
security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids]
136136
subnets = module.public_subnets.public_subnet_id
137+
with_target_group = true
138+
137139

138140
listeners = [
139141
{

_example/nlb/example.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ module "nlb" {
135135
instance_count = module.ec2.instance_count
136136
subnets = module.public_subnets.public_subnet_id
137137
enable_deletion_protection = false
138+
with_target_group = true
138139

139140
target_id = module.ec2.instance_id
140141
vpc_id = module.vpc.vpc_id

main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ resource "aws_lb" "main" {
6060
# Module : LOAD BALANCER LISTENER HTTPS
6161
# Description : Provides a Load Balancer Listener resource.
6262
resource "aws_lb_listener" "https" {
63-
count = var.enable == true && var.https_enabled == true && var.load_balancer_type == "application" ? 1 : 0
63+
count = var.enable == true && var.with_target_group && var.https_enabled == true && var.load_balancer_type == "application" ? 1 : 0
6464

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

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

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

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

182182
target_group_arn = element(aws_lb_target_group.main.*.arn, count.index)
183183
target_id = element(var.target_id, count.index)
184184
port = var.target_group_port
185185
}
186186

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

190190
target_group_arn = element(aws_lb_target_group.main.*.arn, count.index)
191191
target_id = element(var.target_id, 0)

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,8 @@ variable "https_listener_rules" {
371371
default = []
372372
}
373373

374+
variable "with_target_group" {
375+
type = bool
376+
default = true
377+
description = "Create LoadBlancer without target group"
378+
}

0 commit comments

Comments
 (0)