[Bug]: Terraform plan should give you the error if you are using HTTPS as the protocol while creating aws_lb_target_group and aws_lb_listener and do not provide certificate ARN #31371
When using HTTPS as the protocol in the aws_lb_listener & aws_lb_target_group and if we don't specify the certificate_arn then terraform plan is not giving the error. When you run terraform apply then only it is giving the error.
Actual Behavior
When using HTTPS as the protocol in the aws_lb_listener & aws_lb_target_group and if we don't specify the
certificate_arn then terraform plan should give the error that certificate_arn is not defined.
Relevant Error/Panic Output Snippet
Terraform plan is not giving error:
# module.alb.aws_lb_listener.application_load_balancer_listener will be created
+ resource "aws_lb_listener" "application_load_balancer_listener" {
+ arn = (known after apply)
+ id = (known after apply)
+ load_balancer_arn = (known after apply)
+ port = 8000
+ protocol = "HTTPS"
+ ssl_policy = (known after apply)
Plan: 25 to add, 0 to change, 0 to destroy.
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
C02CR96VMD6M:Splunk_Infrastructure dhruvins$
Terraform apply is giving the error
Error: creating ELBv2 Listener (arn:aws:elasticloadbalancing:us-east-2:765631733981:loadbalancer/app/buttercupgames-alb/12352cf60cf3918b): ValidationError: A certificate must be specified for HTTPS listeners
│ status code: 400, request id: f768511e-c630-47e0-88b1-cfce7b1d4965
│
Terraform Configuration Files
# Create listener
resource "aws_lb_listener" "application_load_balancer_listener" {
load_balancer_arn = aws_lb.application_load_balancer.arn
port = 8000
protocol = "HTTPS"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.alb_target_group.arn
}
tags = {
Name = "${var.project_name}-alb-listener"
Env = var.env
Type = var.type
}
}
# Create target group
resource "aws_lb_target_group" "alb_target_group" {
name = "${var.project_name}-tg-group"
port = 8000
protocol = "HTTPS"
vpc_id = var.vpc_id
lifecycle {
create_before_destroy = true
}
health_check {
healthy_threshold = var.health_check["healthy_threshold"]
interval = var.health_check["interval"]
unhealthy_threshold = var.health_check["unhealthy_threshold"]
timeout = var.health_check["timeout"]
path = var.health_check["path"]
port = var.health_check["port"]
}
tags = {
Name = "${var.project_name}-alb-target-group"
Env = var.env
Type = var.type
}
}
Steps to Reproduce
Create application load balancer using terraform
Example snippet:
# Create listener
resource "aws_lb_listener" "application_load_balancer_listener" {
load_balancer_arn = aws_lb.application_load_balancer.arn
port = 8000
protocol = "HTTPS"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.alb_target_group.arn
}
tags = {
Name = "${var.project_name}-alb-listener"
Env = var.env
Type = var.type
}
}
# Create target group
resource "aws_lb_target_group" "alb_target_group" {
name = "${var.project_name}-tg-group"
port = 8000
protocol = "HTTPS"
vpc_id = var.vpc_id
lifecycle {
create_before_destroy = true
}
health_check {
healthy_threshold = var.health_check["healthy_threshold"]
interval = var.health_check["interval"]
unhealthy_threshold = var.health_check["unhealthy_threshold"]
timeout = var.health_check["timeout"]
path = var.health_check["path"]
port = var.health_check["port"]
}
tags = {
Name = "${var.project_name}-alb-target-group"
Env = var.env
Type = var.type
}
}
Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
If you are interested in working on this issue, please leave a comment.
If this would be your first contribution, please review the contribution guide.
Terraform Core Version
1.4.6
AWS Provider Version
4.67.0
Affected Resource(s)
aws_lb_listener aws_lb_target_group
Expected Behavior
When using HTTPS as the protocol in the aws_lb_listener & aws_lb_target_group and if we don't specify the certificate_arn then terraform plan is not giving the error. When you run terraform apply then only it is giving the error.
Actual Behavior
When using HTTPS as the protocol in the aws_lb_listener & aws_lb_target_group and if we don't specify the certificate_arn then terraform plan should give the error that certificate_arn is not defined.
Relevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
Create application load balancer using terraform
Example snippet:
Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
No response
Would you like to implement a fix?
None