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.75k stars 9.11k forks source link

`name_prefix` is almost useless for `aws_alb_target_group` #1666

Open zero-below opened 7 years ago

zero-below commented 7 years ago

Terraform v0.10.4 aws_alb_target_group -- name_prefix creates a 26 character random string after the prefix. However, AWS seems to only accept a max of 32 characters for this resource, leaving only 6 characters for prefix.

It may make sense to cut the random string to something more like 10-16 characters.

aws_alb_target_group.accounts-api: Error creating ALB Target Group: ValidationError: Target group name 'dev3-api00ab7d2fbb5e69734f62409381' cannot be longer than '32' characters

Ninir commented 7 years ago

Hi @zero-below

Thanks for opening this issue.

A good thing could be to generate a string that is 32 - len(name_prefix), so if you have a prefix hello-world-foo-bar-, we would need to generate a string of 12 chars.

What do you think?

alexrudd commented 6 years ago

Work around I've been using:

resource "aws_alb_target_group" "tg" {
name  = "${substr(format("%s-%s", "${var.prefix}-tg", replace(uuid(), "-", "")), 0, 32)}"
...

lifecycle {
    create_before_destroy = true
    ignore_changes        = ["name"]
  }
}
zero-below commented 6 years ago

@Ninir Sorry for the slow response, for some reason I didn't see your reply.

That solution seems to be good.

If you cap the random string at the current 26 characters, then it will also prevent any changes for people who previously had <6 char names.

As a side note, I've found a sprinkling of other resources that also have the 32 char limit, though I unfortunately didn't take notes. I bring this up because it's probably something that a number of AWS resources will end up needing to have implemented.

dev-head commented 6 years ago

Looks like this is stalling, can we please give this some love? the PR is there just waiting for it to be merged in.

@AlexRudd 's workaround is valid, however it prevents changes on the name attribute and if we need to rename it, we've got to manually comment out the life cycle block in a module.

github-actions[bot] commented 4 years ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

Dmitry1987 commented 4 years ago

what's the status of this? Just got an error of

Error: "name_prefix" cannot be longer than 6 characters

Looks like there's still an issue with alb_target_groups?

bholzer commented 4 years ago

I have copied the pull request to the new repo that is home to this functionality: https://github.com/hashicorp/terraform-plugin-sdk/pull/508

RothAndrew commented 4 years ago

Work around I've been using:

resource "aws_alb_target_group" "tg" {
name  = "${substr(format("%s-%s", "${var.prefix}-tg", replace(uuid(), "-", "")), 0, 32)}"
...

lifecycle {
    create_before_destroy = true
    ignore_changes        = ["name"]
  }
}

Here's a better approach that avoids having to use the lifecycle block:

resource "random_uuid" "some_uuid" {}

resource "aws_alb_target_group" "tg" {
  name  = "${substr(format("%s-%s", "${var.prefix}-tg", replace(random_uuid.some_uuid.result, "-", "")), 0, 32)}"
github-actions[bot] commented 2 years ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

jakesmart-drizly commented 2 years ago

Please fix this

pauldraper commented 1 year ago

Here's a better approach that avoids having to use the lifecycle block

Not really.

name_prefix allows replacing a resource using create before destroy. This doesn't help with that issue.

ralucado commented 1 year ago

We are also having issues because of this

rocky-foreflight commented 2 months ago

Please fix this