Replies: 5 comments 13 replies
-
Love this idea @perpil! 🙌 It would be really helpful to have a general naming utility for resources, since the naming constraints on different clouds can vary. @eladb previously suggested an API that allows name generation to be customized with different options... here's a sketch: export class NameGenerator {
// register a name generator for a specific scope
// normally this will be called at the root
public static register(scope: Construct, gen: INameGenerator) {...}
// returns the name generator associated with the current scope
public static of(scope: Construct): INameGenerator {..}
}
export interface INameGenerator {
// default naming scheme
make(resource: Construct, opts?: Options): string;
// DNS-compatible naming (opts can be used to customize)
makeDns(resource: Construct, opts?: Options): string;
makeAzure(r: Construct, o?: Options): string;
makeGcp(r: Construct, o?: Options): string;
// ...
}
//
export interface Options {
readonly minLen?: number;
readonly maxLen?: number;
readonly lowercase?: boolean;
readonly uppercase?: boolean;
readonly dots?: boolean;
readonly hyphens?: boolean;
readonly nonalpha?: boolean;
// ...
// usage
const bucketName = NameGenerator.of(this).makeDns(this); Maybe this could fit somewhere in the core of the SDK? In cases where we can't control resource names, we could also try and fall back to tagging on AWS for example. |
Beta Was this translation helpful? Give feedback.
-
Digging a bit into details here. The CDK uses ID and Path like this: root/ # (ID=root, PATH=root)
cloud.Bucket # (ID=cloud.Bucket, PATH=root/cloud.Bucket)
cloud.Queue # (ID=cloud.Queue, PATH=root/cloud.Queue)
cloud.Queue-OnMessage-bd2fcb591d7f8d4d/ # (ID=cloud.Queue-OnMessage-bd2fcb591d7f8d4d, PATH=root/cloud.Queue-OnMessage-bd2fcb591d7f8d4d)
Code # (ID=Code, PATH=root/cloud.Queue-OnMessage-bd2fcb591d7f8d4d/Code) Now, imagine an app with tens of functions, along with tens of resources with ID root/ # (ID=root, PATH=root)
cloud.Bucket # (ID=cloud.Bucket, PATH=root/cloud.Bucket)
cloud.Queue # (ID=cloud.Queue, PATH=root/cloud.Queue)
cloud.Queue-OnMessage-bd2fcb591d7f8d4d/ # (ID=cloud.Queue-OnMessage-bd2fcb591d7f8d4d, PATH=root/cloud.Queue-OnMessage-bd2fcb591d7f8d4d)
Code # (ID=Code, PATH=root/cloud.Queue-OnMessage-bd2fcb591d7f8d4d/Code)
AnotherQueue1 # (ID=AnotherQueue1, PATH=root/cloud.Queue)
AnotherQueue1-OnMessage-5d334a6dc589a1bf/ # (ID=AnotherQueue1-OnMessage-5d334a6dc589a1bf, PATH=root/AnotherQueue1-OnMessage-5d334a6dc589a1bf)
Code # (ID=Code, PATH=root/AnotherQueue1-OnMessage-5d334a6dc589a1bf/Code)
AnotherQueue2 # (ID=AnotherQueue2, PATH=root/cloud.Queue)
AnotherQueue2-OnMessage-f812794000c38841/ # (ID=AnotherQueue2-OnMessage-f812794000c38841, PATH=root/AnotherQueue2-OnMessage-f812794000c38841)
Code # (ID=Code, PATH=root/AnotherQueue2-OnMessage-f812794000c38841/Code) The What if we use the following naming convention:
This ID is now meaningful enough to know which resource it represents, and also is distinguishable from any other resource which shares the same name. Also, the meaning of the names are proper now: name is not unique, and ID is indeed unique. |
Beta Was this translation helpful? Give feedback.
-
Hey @perpil, going back to the use case:
I was wondering about the role of aws tags in respect to this use case? For example, in the case of a
|
Beta Was this translation helpful? Give feedback.
-
Adding a note here that you can see the impact of generated names in the GSG. Instead of saying go to the queue |
Beta Was this translation helpful? Give feedback.
-
@perpil , I've noticed @marciocadev is working on #1078 I suggest you take a peek on the pull request |
Beta Was this translation helpful? Give feedback.
-
Summary
Make names of cloud resources human friendly
Feature Spec
This isn't really a spec, more of a placeholder to start the discussion. The names of the resources wing creates in the cloud are auto-generated and not human friendly. Furthermore, there doesn't seem to be a property that allows them to be set by the developer (I looked through the doc, but didn't see a name field). I'd like at the minimum to be able to specify resource names so I'm not looking in buckets like:
terraform-20221125051333963700000005
. Ideally there would be some automatic naming too that is more grok-able than a uuid. I'm not sure whether you need a high level entity like a project to help with this, but maybeaccount-region-project-stage-name
.Use Cases
Allow humans to interact with the resources and be able to programmatically generate resource names to integrate with outside tools instead of needing a mapping file.
Implementation Notes
No response
Component
No response
Beta Was this translation helpful? Give feedback.
All reactions