I am trying to get the already created ALB using the data source in terraform and then updating the listener for port 443 but when I do it, it says listener already created. The problem is that I am creating a new listener can't really figure out how to update the listener or overwrite the previous one (ALB is not created using the terraform previously). Any help would be appreciated.
data "aws_lb" "alb" {
arn = var.alb.lb_arn
name = var.alb.lb_name
}
data "aws_lb_target_group" "tg" {
arn = var.alb.lb_tg_arn
name = var.alb.lb_tg_name
}
module "alb" {
source = "./modules/alb"
load_balancer_arn = data.aws_lb.alb.arn
port = var.alb.port
protocol = var.alb.protocol
certificate_arn = module.route53-acm.acm_output.arn
default_action = var.alb.default_action
}
main.tf
resource "aws_lb_listener" "front_end" {
load_balancer_arn = var.load_balancer_arn
port = var.port
protocol = var.protocol
certificate_arn = var.certificate_arn
default_action {
type = var.default_action.type
fixed_response {
content_type = var.default_action.fixed_response.content_type
message_body = var.default_action.fixed_response.message_body
status_code = var.default_action.fixed_response.status_code
}
}
}
can't really figure out how to update the listener or overwrite the previous one (ALB is not created using the terraform previously).
You can't. This is not how TF works. Your ALB must be managed by TF for it to be able to modify. You can import it to TF if you want.
The only other way would be through local exec where you would have to use AWS CLI to modify the existing ALB.