Skip to content

Commit 55811b6

Browse files
committed
don't create test resources if you aren't using codedeploy. They aren't useful because 'terraform apply' updates the live alias
1 parent 8ff157c commit 55811b6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ resource "aws_alb_target_group" "tg" {
8080
}
8181

8282
resource "aws_alb_target_group" "tst_tg" {
83+
count = var.use_codedeploy ? 1 : 0
8384
name = "${local.long_name}-tst"
8485
target_type = "lambda"
8586
tags = var.tags
@@ -104,13 +105,14 @@ resource "aws_alb_listener" "https" {
104105
}
105106

106107
resource "aws_alb_listener" "test_https" {
108+
count = var.use_codedeploy ? 1 : 0
107109
load_balancer_arn = aws_alb.alb.arn
108110
port = 4443
109111
protocol = "HTTPS"
110112
certificate_arn = var.https_certificate_arn
111113
default_action {
112114
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
114116
}
115117
lifecycle {
116118
ignore_changes = [default_action[0].target_group_arn]
@@ -144,11 +146,12 @@ resource "aws_lambda_permission" "with_lb" {
144146
}
145147

146148
resource "aws_lambda_permission" "with_tst_lb" {
149+
count = var.use_codedeploy ? 1 : 0
147150
statement_id = "AllowExecutionFromlb"
148151
action = "lambda:InvokeFunction"
149152
function_name = aws_lambda_function.api_lambda.arn
150153
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
152155
}
153156

154157
resource "aws_alb_target_group_attachment" "live_attachment" {
@@ -158,7 +161,8 @@ resource "aws_alb_target_group_attachment" "live_attachment" {
158161
}
159162

160163
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
162166
target_id = aws_lambda_function.api_lambda.arn # Latest
163167
depends_on = [aws_lambda_permission.with_tst_lb]
164168
}

0 commit comments

Comments
 (0)