Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming conflict when modifying target groups #109

Open
shinenelson opened this issue Dec 13, 2021 · 2 comments
Open

Naming conflict when modifying target groups #109

shinenelson opened this issue Dec 13, 2021 · 2 comments
Labels
bug 🐛 An issue with the system

Comments

@shinenelson
Copy link

shinenelson commented Dec 13, 2021

The Bug

When modifying target group parameters and the target group has to be replaced, terraform apply fails.

Error: error creating LB Target Group: DuplicateTargetGroupName: A target group with the same name 'test-web-application-default' exists, but with different settings
        status code: 400, request id: [redacted]

Expected Behavior

The target group should be replaced without errors

Steps to Reproduce

  1. Provision module
  2. Update any target group parameters that will force the target group to be replaced ( target_group_port, target_group_protocol, target_group_target_type )
  3. terraform apply

Relevant Output

terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement
+/- create replacement and then destroy

Terraform will perform the following actions:

  # module.test_web_application.aws_security_group_rule.ingress must be replaced
-/+ resource "aws_security_group_rule" "ingress" {
      - cidr_blocks              = [] -> null
      ~ from_port                = 80 -> 8080 # forces replacement
      ~ id                       = "sgrule-19963884" -> (known after apply)
      - ipv6_cidr_blocks         = [] -> null
      - prefix_list_ids          = [] -> null
      ~ to_port                  = 80 -> 8080 # forces replacement
        # (5 unchanged attributes hidden)
    }

  # module.test_web_application.module.web_application.aws_lb_listener.https[0] will be updated in-place
  ~ resource "aws_lb_listener" "https" {
        id                = "arn:aws:elasticloadbalancing:[redacted-region:redacted-account-id]:listener/app/test-web-application/9414d30cd6743a52/264e2cdfabc4d33a"
        tags              = {}
        # (7 unchanged attributes hidden)

      ~ default_action {
          ~ target_group_arn = "arn:aws:elasticloadbalancing:[redacted-region:redacted-account-id]:targetgroup/test-web-application-default/ba3a15c19f97afcc" -> (known after apply)
            # (2 unchanged attributes hidden)
        }
    }

  # module.test_web_application.module.web_application.aws_lb_target_group.default[0] must be replaced
+/- resource "aws_lb_target_group" "default" {
      ~ arn                                = "arn:aws:elasticloadbalancing:[redacted-region:redacted-account-id]:targetgroup/test-web-application-default/ba3a15c19f97afcc" -> (known after apply)
      ~ arn_suffix                         = "targetgroup/test-web-application-default/ba3a15c19f97afcc" -> (known after apply)
      ~ id                                 = "arn:aws:elasticloadbalancing:[redacted-region:redacted-account-id]:targetgroup/test-web-application-default/ba3a15c19f97afcc" -> (known after apply)
      ~ load_balancing_algorithm_type      = "round_robin" -> (known after apply)
        name                               = "test-web-application-default"
      ~ port                               = 80 -> 8080 # forces replacement
      + preserve_client_ip                 = (known after apply)
      ~ protocol_version                   = "HTTP1" -> (known after apply)
        tags                               = {
            "Attributes"  = "default"
            "Environment" = "test"
            "Name"        = "test-web-application-default"
        }
        # (8 unchanged attributes hidden)


      ~ stickiness {
            # (3 unchanged attributes hidden)
        }
        # (1 unchanged block hidden)
    }

Plan: 2 to add, 1 to change, 2 to destroy.

module.test_web_application.aws_security_group_rule.ingress: Destroying... [id=sgrule-19963884]
module.test_web_application.module.web_application.aws_lb_target_group.default[0]: Creating...
module.test_web_application.aws_security_group_rule.ingress: Destruction complete after 1s
module.test_web_application.aws_security_group_rule.ingress: Creating...
module.test_web_application.aws_security_group_rule.ingress: Creation complete after 1s [id=sgrule-1287932633]

Error: error creating LB Target Group: DuplicateTargetGroupName: A target group with the same name 'test-web-application-default' exists, but with different settings
        status code: 400, request id: [redacted]

Environment

  • OS: macOS 12.0.1
  • Terraform Version : v0.14.5
  • Module Version : 0.35.3

Additional Context

I suspect this happens because the resource has a create_before_destroy lifecycle and uses a name argument when it should be using a name_prefix.

@shinenelson shinenelson added the bug 🐛 An issue with the system label Dec 13, 2021
@tbpoetke
Copy link
Contributor

tbpoetke commented Jul 28, 2022

same problem here, there is progress for this bug?

@advissor
Copy link

This issue still seems to be occurring (Terraform 1.3.4 here)

Plan: 2 to add, 9 to change, 2 to destroy.

module.alb.aws_lb_target_group.default[0]: Creating...
module.alb.aws_lb.default[0]: Modifying... [id=arn:aws:elasticloadbalancing:us-east-1:111111111111111:loadbalancer/app/]
module.alb.aws_lb.default[0]: Modifications complete after 31s [id=arn:aws:elasticloadbalancing:us-east-1:111111111111111:loadbalancer/app]


creating LB Target Group: DuplicateTargetGroupName: A target group with the same name 'opera-dev-ecs-alb-serv-23213' exists, but with different settings
│       status code: 400, request id: 2a22bb2e-a202-2ec2-22e2-2222a22c22f
│ 
│   with module.alb.aws_lb_target_group.default[0],
│   on .terraform/modules/alb/main.tf line 109, in resource "aws_lb_target_group" "default":
│  109: resource "aws_lb_target_group" "default" {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

3 participants