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

Randomness added to resource names when using name_prefix can cause names to be too long #12947

Closed
joshuaspence opened this issue Mar 21, 2017 · 6 comments

Comments

@joshuaspence
Copy link
Contributor

I've been working on adding name_prefix to a bunch of AWS resources lately so that multiple environments can reside in the same stack. One problem that I've come across lately is that some AWS resources have quite a small limit on the length of the name property. I raised this issue in #12629 and was advised to create a new issue (CC @stack72). For example, the maximum length for an autoscaling group name is 32 characters. This means that the maximum length of the name_prefix is a measly 6 characters.

One way that we could work around this would be to use truncate the name so that it doesn't exceed the maximum length. So if the maximum length is 32 characters and I provide a name_prefix which is 16 characters, I would only get 16 characters of randomness.

I'm happy to work on implementing a solution if we can agree on one.

@ColinHebert
Copy link
Contributor

Hey @joshuaspence are you still keen on working on that? I'm happy with that proposal as it leaves the responsibility of the increase in collisions to the person who defines the resource.

@stack72 what do you think?

@joshuaspence
Copy link
Contributor Author

I haven't implemented anything yet because I wasn't sure how the upstream felt about my proposal.

@pmoust
Copy link
Contributor

pmoust commented May 30, 2017

@joshuaspence I would welcome such improvement.

I am not sure if the change should come into PrefixedUniqueId func by changing the signature of the function adding a limit as int, or only into any given resource's name_prefix attribute func.

That's the only bit I supose that maintainers should guide your way; who was the responsibility for truncating the extra bits.

@apparentlymart
Copy link
Contributor

Hi @joshuaspence! Sorry for the silence here.

This is a tough one because it seems to sit squarely on the tension in Terraform about being explicit about what is going to happen vs. including helpful behaviors to smooth over oddness in underlying APIs.

One way we could address this tension is to specify am explicit maximum length for name_prefix and then set the length of the random suffix with that in mind. In your example you give a 16/16 split, which seems on the surface to be a reasonable tradeoff. What do you think about forcing a max length of 16 characters on name_prefix and then generating only 16 digits of randomness? This way we can still generate an error if the prefix is too long, rather than silently increasing the chance of collisions, but permit more expressiveness in the name prefix.

@derFunk
Copy link

derFunk commented Jun 4, 2017

I just fell over this as well.

Firstly: It's still not documented in https://www.terraform.io/docs/providers/aws/r/alb_target_group.html#name_prefix that the name_prefix should be max 6 characters.

Secondly: 6 characters is not enough. I'm using prefixes and suffixes and stuff for my resource names, e.g. fe-myapp-dev-tg for a Target Group.

--> The character length of the appended random string should be reduced by len(name_prefix).

For Reference: https://github.com/hashicorp/terraform/pull/13442/files#r110410247

@ghost
Copy link

ghost commented Apr 9, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants