former2 icon indicating copy to clipboard operation
former2 copied to clipboard

Logical resource naming within the template

Open reidca opened this issue 5 years ago • 8 comments

I created a template for our VPC using Former2.

I added all related resources I could think of as well as those suggested by Former2.

This resulted in a large template, over 500 lines long and a lot of resources.

Because all the resources have random logical names it can make identifying them difficult when looking at the template. Although I understand that you could not possibly infer the logical name with anything meaningful, I think it would be useful to put the type of the resource somewhere in the name to at least give some semantic meaning to the resources.

e..g. instead of a resource being called ec26de3980, call it VPCGatewayAttachmentec26de3980

This would help human comprehension of the template, especially when looking at what REF and GetAtt are referring to.

Thanks!

reidca avatar Feb 12 '20 16:02 reidca

Thanks for the suggestion @reidca!

I've thought previously about some better naming for these resources, perhaps by using some of the primary identifiers returned from !Ref for example. I've also considered a custom templating solution where you could pick your own pattern that suits you.

The resource name is indeed probably more appropriate and it's what CDK uses, though I do find that slightly long (they also discuss this same issue).

Give me some time to consider good alternatives :thinking:

iann0036 avatar Feb 13 '20 06:02 iann0036

Agreed it does lead to long names but I think on the whole this is preferable to a resource with no inferable meaning as it currently stands. Thanks.

reidca avatar Feb 13 '20 09:02 reidca

I have just completed my first "Import" of my manually modified template. On the dialog where it asks you for the ids of the resources to import I am not sure how it would have been possible for me to input the correct ids without me having renamed the logical ids prior to this.

e.g. for subnets. I name them something like SubnetAPrivate which gives some semantic meaning to the resource and then when fetching the id I can look in the console for the Private subnet in AZ A. If the name was just a hash it would have required more lookups.

I know this is not easy to achieve and the naming may in some cases depend on the type of resource being generated such as in this case. given the number of resource types this would be difficult to achieve.

Happy to help play around with ideas or test.

reidca avatar Feb 13 '20 10:02 reidca

Would a setting/preference suffice? There's probably a few strategies that could be implemented here:

Screen Shot 2020-02-13 at 10 01 10 pm

iann0036 avatar Feb 13 '20 11:02 iann0036

I think that would be very useful. If there is a way of adding overrides through the UI that would also be great although I appreciate that may present a challenge!

reidca avatar Feb 13 '20 11:02 reidca

Hey @reidca,

Just got the new logical ID naming strategies in (58cb9b234731ebb596288f7faba84c4321c40e71).

Give it a shot and let me know what you think!

iann0036 avatar Feb 15 '20 07:02 iann0036

Hi Ian, firstly amazing work this is an awesome tool :)

Is it possible to use the Name tag as the logical ID in the generated template?

Or, for the benefit of those downloading the template and importing manually the resourceID as the logicalID suffix? This would make it easy to copy paste the resourceID's on the Import page in Cloudformation. NameTag-ResourceID might be ideal.

hodgsonsam avatar Dec 09 '20 11:12 hodgsonsam

Hey @hodgsonsam,

Thanks for the suggestion!

I think a new naming strategy based on the "Name" tag, where available, would be great. Happy to put this on the roadmap.

On importing, many resources do need more than one property value to properly identify the resource, so this may not be a foolproof strategy. There is an import feature available straight from the CloudFormation outputs screen that manages the change set creation (and optionally, deployment) process for you.

iann0036 avatar Dec 09 '20 11:12 iann0036