@@ -80,6 +80,7 @@ resource "aws_alb_target_group" "tg" {
80
80
}
81
81
82
82
resource "aws_alb_target_group" "tst_tg" {
83
+ count = var. use_codedeploy ? 1 : 0
83
84
name = " ${ local . long_name } -tst"
84
85
target_type = " lambda"
85
86
tags = var. tags
@@ -104,13 +105,14 @@ resource "aws_alb_listener" "https" {
104
105
}
105
106
106
107
resource "aws_alb_listener" "test_https" {
108
+ count = var. use_codedeploy ? 1 : 0
107
109
load_balancer_arn = aws_alb. alb . arn
108
110
port = 4443
109
111
protocol = " HTTPS"
110
112
certificate_arn = var. https_certificate_arn
111
113
default_action {
112
114
type = " forward"
113
- target_group_arn = aws_alb_target_group. tst_tg . arn
115
+ target_group_arn = aws_alb_target_group. tst_tg [ 0 ] . arn
114
116
}
115
117
lifecycle {
116
118
ignore_changes = [default_action [0 ]. target_group_arn ]
@@ -144,11 +146,12 @@ resource "aws_lambda_permission" "with_lb" {
144
146
}
145
147
146
148
resource "aws_lambda_permission" "with_tst_lb" {
149
+ count = var. use_codedeploy ? 1 : 0
147
150
statement_id = " AllowExecutionFromlb"
148
151
action = " lambda:InvokeFunction"
149
152
function_name = aws_lambda_function. api_lambda . arn
150
153
principal = " elasticloadbalancing.amazonaws.com"
151
- source_arn = aws_alb_target_group. tst_tg . arn
154
+ source_arn = aws_alb_target_group. tst_tg [ 0 ] . arn
152
155
}
153
156
154
157
resource "aws_alb_target_group_attachment" "live_attachment" {
@@ -158,7 +161,8 @@ resource "aws_alb_target_group_attachment" "live_attachment" {
158
161
}
159
162
160
163
resource "aws_alb_target_group_attachment" "tst_attachment" {
161
- target_group_arn = aws_alb_target_group. tst_tg . arn
164
+ count = var. use_codedeploy ? 1 : 0
165
+ target_group_arn = aws_alb_target_group. tst_tg [0 ]. arn
162
166
target_id = aws_lambda_function. api_lambda . arn # Latest
163
167
depends_on = [aws_lambda_permission . with_tst_lb ]
164
168
}
0 commit comments