hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.76k stars 9.12k forks source link

[Bug]: Implicit import of aws_lb_listener instead of error "A listener already exists on this port for this load balancer" #35121

Open dga-nagra opened 9 months ago

dga-nagra commented 9 months ago

Terraform Core Version

1.6.6

AWS Provider Version

5.3.1

Affected Resource(s)

Expected Behavior

I expect the error

A listener already exists on this port for this load balancer ... To be raised

Actual Behavior

No error is raised and the ARN output is the same. Previously added rules are lost silently.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.31"
    }
  }
}

provider "aws" {
  # Configuration options
  region = "eu-west-1"
}

resource "aws_lb_listener" "https" {
  load_balancer_arn = data.aws_lb.test.arn
  port              = "443"
  protocol          = "HTTPS"
  ssl_policy        = "..."  # Any ssl policy
  certificate_arn   = "..."  # Any certificate arn
  default_action {
    type = "fixed-response"
    fixed_response {
      content_type = "text/plain"
      message_body = "Invalid request"
      status_code  = "200"
    }
  }
}

output "aws_lb_listener_created" {
  value = "Listener arn: ${aws_lb_listener.https.arn}"
}

Steps to Reproduce

I have the following same definition in 2 different terraform projects but working on the same AWS account. image

I run one of the terraform project, then, once the first one is finished, I run the second one. The output is the same and no error was raised.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 9 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

acwwat commented 8 months ago

I suspect that this is an upstream bug. I am able to reproduce the problem using the AWS CLI. Running a similar command below multiple time would succeed instead of failing with a DuplicateListener error as described in the CreateListener API reference. I would recommend opening an AWS Support ticket and have AWS look at the server side of the API.

Note that I also tried reproducing the problem in AWS Management Console and it returns a "You may not have duplicate ports defined." warning for the port field on submit. Although that's probably just UI validation.

aws elbv2 create-listener --load-balancer-arn <alb-arn> --port 80 --protocol HTTP --default-actions Type=forward,TargetGroupArn=<http-target-group-arn>
rafael-debug commented 3 months ago

Hey, guys, I'm also having this same problem. A listener already exists on this port for this load balancer in CLI and console it works fine.

adampoplawski commented 2 months ago

I have same issues on 1.9.2. We were adding listeners this way already before.