Terraform-provider-aws: Unable to modify alb target group using terraform

Created on 13 Jun 2017  ยท  5Comments  ยท  Source: hashicorp/terraform-provider-aws

_This issue was originally opened by @amolsh as hashicorp/terraform#13313. It was migrated here as part of the provider split. The original body of the issue is below._


Hi,
I am using terraform 0.9.2. I created alb target group as follows

```
"aws_alb_target_group" "cachet-alb-tg" {
name = "lab-cachet-alb-tg"
port = 80
protocol = "HTTP"
vpc_id = "${var.vpc_id}"

health_check {
    matcher = "200,302"
    timeout = 20
    unhealthy_threshold = 5
}

stickiness {
    type   = "lb_cookie"
}

tags {
      Name = "cachet-alb-tg"
      business_unit = "ghs"
      product_line = "ALM"
      owner = "shendea"
      environment = "test"
}

}




Now I wanted modify my config and change port from 80 to 8000. So, new config is

resource "aws_alb_target_group" "cachet-alb-tg" {
name = "lab-cachet-alb-tg"
port = 8000
protocol = "HTTP"
vpc_id = "${var.vpc_id}"

health_check {
    matcher = "200,302"
    timeout = 20
    unhealthy_threshold = 5
}

stickiness {
    type   = "lb_cookie"
}

tags {
      Name = "cachet-alb-tg"
      business_unit = "ghs"
      product_line = "ALM"
      owner = "shendea"
      environment = "test"
}

}

```
Now, When I use terraform apply. It throws following error:

aws_alb_target_group.cachet-alb-tg: Error creating ALB Target Group: DuplicateTargetGroupName: A target group with the same name 'lab-cachet-alb-tg' exists, but with different settings
status code: 400,

bug

Most helpful comment

name_prefix of 6 characters is really inconvenient

All 5 comments

Strange, I only encountered a similar issue when "create before destroy" was set.
My solution was to use name_prefix instead of name (I think it is generally a good idea).

Sorry for the confusion here!
Many of the attributes of aws_alb_target_group are set to be ForceNew, meaning that changing their value results in the destruction and creation of a new resource. The name attribute of aws_alb_target_group must be unique as well, so if you're using create_before_destroy lifecycle, you need to use the name_prefix as @scream314 mentions, or you will attempt to create a new resource with the same name before destroying the old one, which will error.

The error above is the result of trying to create a resource of the same name. IF you're not using the create_before_destroy lifecycle block, then there could be an issue where the resource name sticks around in AWS for a time.

Please use the name_prefix attribute instead of the name attribute to avoid this.

Let me know if you have any questions!

Hi @catsby

name_prefix has a character limit of 6 character (According to the docs)
This does not work if you have a naming convention longer then 6 character

What do we do when we have that usecase?

name_prefix of 6 characters is really inconvenient

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings