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

The name for aws_lb_target_group.alb_target_group is too long and is easy to hit an aws limit #161

Open
JoeJasinski opened this issue Feb 24, 2024 · 0 comments

Comments

@JoeJasinski
Copy link

JoeJasinski commented Feb 24, 2024

Hey all, I'm running into an issue where the target group name is too long for AWS, which breaks the deply.

In AWS, target group names are very limited in their length (32 chars). That only allows 15 chars for "prefix" and "cluster_name" combined, or the entire tf apply will fail.

resource "aws_lb_target_group" "alb_target_group" {
  count    = var.create_alb ? 1 : 0
  name     = "${var.prefix}-${var.cluster_name}-lb-target-group"  # <<<<<  THIS IS TOO LONG

A really easy solution for this would be to shorten the name that's generated to something like the following. That would allow 28 characters for the combined prefix+cluster_name.

resource "aws_lb_target_group" "alb_target_group" {
  count    = var.create_alb ? 1 : 0
  name     = "${var.prefix}-${var.cluster_name}-tg"

And/or it might also be a good option to allow a user to specify an alternative target group name as a var, so they can use as long of a prefix+cluster_name that they want, but specify a shorter name for the target group that fits within AWS naming rules.

A final comprehensive solution might be to hash the full target group name value into a short hash. Then, truncate the name and append the hash so it fits within 32 chars. That would allow names of any size (at the expense of the name looking nice)

Here's what I'm trying to express, written in HCL.

> "${substr("myreallylongprefix-myreallylongclustername", 0, 22)}-${substr(sha256("myreallylongprefix-myreallylongclustername"), 0, 6)}-tf"
"myreallylongprefix-myr-bf8a97-tf"

> length("${substr("myreallylongprefix-myreallylongclustername", 0, 22)}-${substr(sha256("myreallylongprefix-myreallylongclustername"), 0, 6)}-tf")
32

Here is the relevant place in the code

name = "${var.prefix}-${var.cluster_name}-lb-target-group"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant