-
-
Notifications
You must be signed in to change notification settings - Fork 316
Proposal: prefix
output
#126
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
Comments
This functionality is there already.
When I’m building modules or terraform I start with a label module that contains only the prefix values.
Then every other label I make I pass the context of that label module to it, and just add the name field, and some times some extra tags.
Then it’s very dry.
But I don’t see a reason not to also add a prefix output.
Regards
Jamie Nelson
-/-
On Apr 7, 2021, at 7:23 AM, Matt Gowie ***@***.***> wrote:
Describe the Feature
I find it common that folks will utilize what I think of as the label's prefix (e.g. ${namespace}-${stage}-${environment}) as a string interpolation prefix to some identifier that they want to create without building a full label.
Most of the time this is used as a crutch to avoid having to create a label module for each namable thing that you're working on. It could definitely be argued that this is a bad practice and that it shouldn't be done... but I've seen it enough now across multiple codebases that I know I'm not the only one who does it so figured this proposal was worth the discussion.
The proposal is to add a new output called prefix that is simply all label components up until the name component. e.g. ${namespace}-${stage}-${environment}, ${namespace}-${stage}, ${namespace}-${environment}, etc.
I would need to look into the code more to determine how we would handle that in regards to the label ordering... but figured I could bring this up for discussion before coming up with a proper solution.
Use Case
This would enable not having to create this label prefix for ad-hoc usages and therefore dry up some terraform string interpolation code.
Alternatives Considered
Alternatives:
1. Don't do this... I'd be fine to hear the feedback here say something along the lines of: Hey that should be considered bad practice and we don't want to support it.
2. Create a prefix label that is only made up of the components that you want instead of outputting the prefix from more specific labels.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@Jamie-BitFlight yeah I get that POV and after getting the thoughts from the wider Cloud Posse team on this I'm going to close out. |
I'm going to reopen this for discussion... I still see it being done and I honestly this it has merit. I'm not sure if this is just me being bull headed and misremember my conversation with the community, but I want this to be discussed here in this issue before calling it closed as I'm coming back this issue years later and still wanting this functionality |
I'm just arriving at this module today after going through a series of ocean boiling attempts to look for a DRY way to manage tags and labels. The pain-point as I see it is less about the proliferation of many module declarations so much as it is the number of variables that have to get propagated along side the functional metadata that defines qualities things like instance type, capacity pre-provisioning, queue type, message count, or whatever size and behavior modifiers are going to be needed to configure the behavior and characteristics of whatever named resources a module is created for. Among the things we've tried are the consolidation of all resource name and tag set generation from a module that receives an index three tiered map, where the outer map is for service type, the second tier is for resource type, and the third tier is for a functional role name that leads to a leaf node object that collects all the values that are distinguish one resource from another:
We had come to find that in some rare cases there are needs for resource-type-specific naming convention changes:
When we started considering the "Workload" dimension in particular, and if our application made more use of multiple regions I suspect, we started to appreciate that there is often some scoping that changes the number of qualifiers we needed in certain scenarios:
We still wanted color and weather as properties we collected in the deployment properties for an instance of this app, but we only wanted to use them in name generation when the purpose was to generate a name for a data resource that would look up a subnet, or a security group, or something else provisioned with VPC-oriented namespacing. For the resourced deployed into the contexts those tokens implied, we only wanted to use them to tag our resources, to configure their CloudMap discovery DNS domain, but we used a different sequence of names to track the logical instances that were being used at any point in time for some development effort. Centralizing all the label construction in a master place initially allowed us to avoid repeating the constant parts of a prefix, but accommodating two or three "Scopes" for selecting the right elements to use started exposing every resource to the semantics of placing themselves in the right scope, which wasn't always easy or intuitive because this central registry was far removed from where the names actually got used. While looking at this repository today tho, I saw something that made me remember something very useful from my functional programing class--currying!! I noticed that for the sake of reusing some parts of a label's definition there seems to be a context output that can be provided as a single input to another label module allocation. I think there may be a lot of value in using that kind of a construct--the ability to configure a module for labelling verbosely close to the application's root to supply the parameter rich patterns that are reused, and possibly to fix the values that are not going to change from one use to another, reducing the state that is needed to reuse the parts of a naming scheme that are locked in by outer modules, while still allowing partial clarification and override at the deeper layers without needing to pass a library of individual attributes. When you think about it, anyone who is using one Module label to create a prefix name and then passing that around is already using a poor man's memento design pattern based on a simple concatenation heuristic. It works for the simplistic case of simple concatenation, and if an application has only three or four naming scopes, it would probably do this three or four times and pass just those prefixes around. But it does so at the loss of tag set propagation, case conversion, and other features. Passing a black box memento from labeling scopes that hide the distinct values needed to reuse the decisions that call for passing the same inputs in otherwise may be a fine compromise--the module call to provide a black box memento plus some minimal local customizations for a related use seems promising as being more usable than needing to receive all the arguments in the full signature and remember to pass them back as well. Potentially it could also provide some future proofing depending on the impact of any new attributes that a caller might start using and then need downstream modules to carry and pass into for their own use. Without having given the implementation details a lot of thought, I can say that there was a certain sense of logical epiphany when I saw the use of "context" and remembered my first exposure to the "Memento" design pattern that is all about externalizing the means to reconstruct an object with a complex creational pattern as an opaque value that can be readily passed around inside of a program and then later supplied back to its original provider class in order to reconstitute the complex object without knowing anything about the complexity involved. We don't have custom functions in Terraform, that would allow us to pass around curried functions, but it seems to me that we do have the means to use a pair of modules to provide implementations of the memento pattern, and it may very well be that labelling fits that design pattern extremely well... Instead of attempting to perform all name generation in a single module that would receive the both the rules metadata that I don't want to repeat alongside all of the inputs I want to generate labels for using those rules, I could use a policy memento module to capture the fixed values and set the required call signature at my root, and then pass as many of these mementos as my submodules need for what scope their naming needs are. For the purpose of using a memento, there are problably at least two kinds of stakeholders:
Anyhow, enough rambling from me for now. I want to download this module and see just how much reuse I can lready get from its context chaining.... |
Distilling the feedback I just offered above a bit, I'll reduce it in volume to a question asking whether there would be any benefit in terms of things like the implementation cost of having one module that has to both apply a naming policy and also construct a context object. I would anticipate that there could be things like this going on in the implementation:
If so, then the law of Demeter may be worth applying here as an observation that constructing the memento to reuse a policy, acting on a memento to perform labelling, and acting on raw input alone to perform labelling are perhaps two or three distinct use cases and merit distinct module entry points.
|
Describe the Feature
I find it common that folks will utilize what I think of as the label's prefix (e.g.
${namespace}-${stage}-${environment}
) as a string interpolation prefix to some identifier that they want to create without building a full label.Most of the time this is used as a crutch to avoid having to create a label module for each namable thing that you're working on. It could definitely be argued that this is a bad practice and that it shouldn't be done... but I've seen it enough now across multiple codebases that I know I'm not the only one who does it so figured this proposal was worth the discussion.
The proposal is to add a new output called
prefix
that is simply all label components up until thename
component. e.g.${namespace}-${stage}-${environment}
,${namespace}-${stage}
,${namespace}-${environment}
, etc.I would need to look into the code more to determine how we would handle that in regards to the label ordering... but figured I could bring this up for discussion before coming up with a proper solution.
Use Case
This would enable not having to create this label prefix for ad-hoc usages and therefore dry up some terraform string interpolation code.
Alternatives Considered
Alternatives:
prefix
label that is only made up of the components that you want instead of outputting the prefix from more specific labels.The text was updated successfully, but these errors were encountered: