Skip to content

Naming conflict when modifying target groups #109

Open
@shinenelson

Description

@shinenelson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions