-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Allow multiple truncated versions of a label #118
Allow multiple truncated versions of a label #118
Conversation
There's an alternate implementation I considered: module "label" {
id_lengths = [16, 32, 64, 128] # default value. Add or remove values as required.
}
module.label.id # unchanged: truncated to `id_length_limit`
module.label.id_trunc[16] # 16 char version
module.label.id_trunc[32] # 32 char version
module.label.id_trunc[48] # Error! You didn't request this length in `id_lengths` It's more configurable, but more complex. Do you think this complexity is worth it? |
How do I run the bats tests locally on macOS? It's not documented as far as I can see. Is it this bats or something else? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #117 (comment) which is along the lines of your #118 (comment)
My concern with this approach is it's not possible to statically detect
errors like "label.id[47]" (when you meant 48). This would result in
run-time errors not picked up during validation. Do you still prefer this
approach?
…On Wed, 6 Jan 2021 at 23:51, Nuru ***@***.***> wrote:
***@***.**** requested changes on this pull request.
See #117 (comment)
<#117 (comment)>
which is along the lines of your #118 (comment)
<#118 (comment)>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#118 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC4U5MLWXOONIHQ7TXH24DSYRMD3ANCNFSM4VXDT4AQ>
.
|
For this particular use-case, I think I agree with @alexjurkiewicz. Having the ability for terraform to statically detect errors is advantageous. Additionally, we get the benefit of automatic documentation. |
@osterman I concur 👍 |
/rebuild-readme |
/test all |
@alexjurkiewicz LGTM, thanks. |
@aknysh done:
|
/test all |
@alexjurkiewicz LGTM. |
One thought I had was removing id128 because it doesn't sort nice in the docs, and really who cares about an id if it's longer than 64 chars anyway? |
Yes, that's what I meant by reviewing one more time :) |
So I really like the idea of pre-defined lengths, but it seems like in true AWS fashion they have picked some odd length limits. Maybe we need to go with a more dynamic approach as @Nuru suggested. |
I was in favor of the fixed size outputs but now wonder if using a simple map to lookup size limits for a given resource type is all that is needed. I really don't want to have to know the limits for each resource type but that is I have been doing. |
This module is cloud-agnostic, I think. So I'm not sure putting all that
data into this module is a good idea.
I'm on holidays a few weeks, but I'll update this PR to use user defined
lengths when I get back.
…On Thu, 21 Jan 2021, 5:22 am Tim Gourley, ***@***.***> wrote:
I was in favor of the fixed size outputs but now wonder if using a simple
map to lookup size limits for a given resource type is all that is needed.
I really don't want to have to know the limits for each resource type but
that is I have been doing.
id_length_limit = local.awsResourceNameLimits["ec2"]
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#118 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC4U5JXJTEJ5MY7UJTKKEDS24NQBANCNFSM4VXDT4AQ>
.
|
I did not mean put the resource type to size mapping in this module. But saying - a convention of using a map to apply the correct size for a resource type would be handy, instead of attempting to hard code it per resource. (that is what I tried to imply at least with the local reference, but I wasn't clear enough.) |
@alexjurkiewicz @osterman @aknysh At this point I'm thinking this is better off published as a separate module:
You would use it as an add-on the module "label" {
source = "cloudposse/label/null"
version = "0.22.1"
attributes = ["example"]
context = module.this.context
}
module "short_label" {
source = "cloudposse/label-truncate/null"
version = "0.1.0"
delimiter = module.label.delimiter
label_full = module.label.id_full
}
locals {
elasticache_id = module.short_label.label_050
aurora_cluster_id = module.short_label.label_063
} The difference between a straightforward chopping off of the string and what this module does is that the module will include a partial hash of the full string, so that the strings will be different even if the substrings are the same, and uses and respects the delimiter, like null-label currently does with the truncated We could even expand on null-label's So it can be complex and sophisticated but only used when needed, so that |
@Nuru probably not a separate module, but a submodule of this one. That submodule should probably only accept |
@osterman I'm not that familiar with publishing a submodule. What are the advantages of that? My thought about publishing it separately is that it is a handy utility anywhere you need to shorten strings while maintaining uniqueness.
|
d8df71c
to
c4bb961
Compare
ff5fbf0
to
fc2205b
Compare
Rebased.
Luckily this merged cleanly, I manually checked and these changes look to be completely uncoupled.
Done ✌️ |
One question. Should I pass the I lean towards: "yes, include it in context and a user-supplied override should replace". |
@alexjurkiewicz All inputs need to be carried forward to the output context to support chaining. For Be sure to include tests where |
Done. Since this is a list of numbers rather than strings the logic is slightly different to attributes, also I added non-null variable validation for individual list elements (since Terraform numbers are nullable).
Done (see label9.tf) |
The only difference between strings and numbers is that you do not have to worry about modifying the numbers.
Sorry that it is not obvious or documented, but it is not enough to create the Terraform for the test, you have to validate the outputs in examples_complete_test.go. Also, please make sure that one of the truncation lengths lines up with a delimiter such that we get an extra character of hash, to verify that that is working. I think 21 will do it for |
@alexjurkiewicz I want to let you know that after spending 3 months and 23 commits to get #107 right (or so we thought), we then found a bunch of other problems leading to a failed v0.23.0 and v0.24.0, and now that we have v0.24.1 out we going to take a break on releasing new features. So we are probably not going to try to include the PR anytime soon. However, if you want to educate yourself, look at all the changes we made after merging #107 just to fix the things we overlooked after spending 3 months and 23 commits trying to get it right. It is a consequence of this being a heavily used module that needs to retain backward compatibility even as we add new features. The more of these lessons you can learn from and incorporate in this PR, the more likely we are to get this released sooner rather than later. |
Thanks. Totally understand. So looks like you want to maintain forwards and backwards compatibility with new versions. Specifically: support passing old contexts into new version and vice versa. Is that right? |
@alexjurkiewicz Yes, that is right. The plan we have is that going forward, the You probably want to rebase this PR on |
This allows creating multiple truncated forms of an ID based on user-specified lengths. For example: variable `id_lengths = [8,16]` results in output `id_trunc = {8 => "...", 16 => "..." }`. This is useful when you want to use the same label for several resources with different length restrictions. Closes cloudposse#117.
If provided an input context without this setting, fall back to the default value ([]).
b89a50f
to
2554778
Compare
Thanks for the feedback. I have made the following changes:
I believe (once again :) ) this addresses everything. Please take a look 🙏 |
I've just added a test for loading an older context. It's the one thing I'm least sure about, since I couldn't base it on any prior art in this module ;) Please check b90a32a's content extra carefully. |
ping |
@alexjurkiewicz I know you have worked hard on this, but I am still not convinced it is worth the extra overhead. I really hope @osterman What do you think? If we were to go forward with this, I would want the |
@alexjurkiewicz I am going to close this and close #117 as "wontfix" because of all the reasons already stated, the main ones being:
|
Truncated forms of id_full which are always available. This is useful
when you want to use the same label for several resources with different
length restrictions.
Closes #117.