Skip to content

Fix TCP target group name exceeding AWS 32-char limit#98

Open
georgidimdimitrov wants to merge 1 commit into
pivotal:releasefrom
georgidimdimitrov:fix-tcp-target-group-name-length
Open

Fix TCP target group name exceeding AWS 32-char limit#98
georgidimdimitrov wants to merge 1 commit into
pivotal:releasefrom
georgidimdimitrov:fix-tcp-target-group-name-length

Conversation

@georgidimdimitrov

Copy link
Copy Markdown

Problem

The aws_lb_target_group.tcp resource currently names target groups as:

"${var.environment_name}-tcp-tg-${1024 + count.index}"

For environment names >= 21 characters (e.g. twilight-paladin-6a43 at 21 chars), the generated name reaches 33+ characters, exceeding AWS's 32-character limit and causing terraform apply to fail:

Error: "name" cannot be longer than 32 characters
  with aws_lb_target_group.tcp[2],
  on pas-lbs.tf line 112

Fix

Use Terraform's substr() to cap the prefix and drop the redundant -tg suffix (the resource type already identifies this as a target group):

name = "${substr(var.environment_name, 0, 19)}-tcp-${1024 + count.index}"

Maximum length: 19 + 5 (-tcp-) + 4 (1028) = 28 chars, safely under the 32-char limit for any environment name.

The current pattern generates names like:
  twilight-paladin-6a43-tcp-tg-1024  (33 chars, > 32 limit)

Use substr to cap the environment name prefix and drop the
redundant -tg suffix:
  substr(env, 0, 19) + -tcp- + port = max 28 chars

Fixes terraform apply failures for environment names >= 21 chars.

Co-authored-by: Cursor <cursoragent@cursor.com>
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

Successfully merging this pull request may close these issues.

1 participant