Skip to content

[Bug]: aws_lb_target_group is created before destruction #35717

Open
@speller

Description

Terraform Core Version

1.5.0

AWS Provider Version

5.25.0

Affected Resource(s)

aws_lb_target_group

Expected Behavior

When I change aws_lb_target_group parameters, it should be destroyed first.

Actual Behavior

TF tries to create new target group before destruction.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_lb_target_group" "group" {
  name = module.infra_name.name_hyphen
  port = var.port
  protocol = "HTTP"
  vpc_id = var.vpc_id
  health_check {
    enabled = true
    path = var.healthcheck.path
    protocol = "HTTP"
    port = var.port
    unhealthy_threshold = 3
    healthy_threshold = 2
    interval = var.healthcheck.interval
    timeout = var.healthcheck.timeout
  }
}

Steps to Reproduce

Make a change that requires aws_lb_target_group recreation

Debug Output

TF log:

Planning:

...
module.***.target_group.aws_lb_target_group.group: Refreshing state... [id=arn:aws:elasticloadbalancing:ap-northeast-1:***:targetgroup/rev-main-fe/81c1915b8d222f2f]
...

The target group is here and TF refreshed its state.

  # module.***.target_group.aws_lb_target_group.group must be replaced
+/- resource "aws_lb_target_group" "group" {
      ~ arn                                = "arn:aws:elasticloadbalancing:ap-northeast-1:***:targetgroup/rev-main-fe/81c1915b8d222f2f" -> (known after apply)
      ~ arn_suffix                         = "targetgroup/rev-main-fe/81c1915b8d222f2f" -> (known after apply)
      ~ connection_termination             = false -> (known after apply)
      ~ id                                 = "arn:aws:elasticloadbalancing:ap-northeast-1:***:targetgroup/rev-main-fe/81c1915b8d222f2f" -> (known after apply)
      ~ ip_address_type                    = "ipv4" -> (known after apply)
      ~ load_balancing_algorithm_type      = "round_robin" -> (known after apply)
      ~ load_balancing_cross_zone_enabled  = "use_load_balancer_configuration" -> (known after apply)
        name                               = "rev-main-fe"
      + name_prefix                        = (known after apply)
      ~ port                               = 3000 -> 8000 # forces replacement
      + preserve_client_ip                 = (known after apply)
      ~ protocol_version                   = "HTTP1" -> (known after apply)
        # (7 unchanged attributes hidden)
      ~ health_check {
          ~ matcher             = "200" -> (known after apply)
          ~ port                = "3000" -> "8000"
            # (7 unchanged attributes hidden)
        }
      - stickiness {
          - cookie_duration = 86400 -> null
          - enabled         = false -> null
          - type            = "lb_cookie" -> null
        }
      - target_failover {}
      - target_health_state {}
    }

Okay, we've changed the port number and the target group is set to be replaced. The name should be unique.

The first line on apply:

module.***.target_group.aws_lb_target_group.group: Creating...

But the old one was not deleted yet, so obviously we get the following error immediately:

│ Error: ELBv2 Target Group (rev-main-fe) already exists
│ 
│   with module.***.module.target_group.aws_lb_target_group.group,
│   on lb-target-group/main.tf line 13, in resource "aws_lb_target_group" "group":
│   13: resource "aws_lb_target_group" "group" {

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/elbv2Issues and PRs that pertain to the elbv2 service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions