troposphere icon indicating copy to clipboard operation
troposphere copied to clipboard

Better Implementation of troposphere API

Open MacHu-GWU opened this issue 6 years ago • 1 comments

@markpeek

The way you implement the AWS Resource Class is this, and it uses customized getattr, setattr method:

class Instance(AWSObject):
    resource_type = "AWS::EC2::Instance"

    props = {
        'Affinity': (str, False),
        'AvailabilityZone': (str, False),
        'BlockDeviceMappings': (list, False),
        'CreditSpecification': (CreditSpecification, False),
        'DisableApiTermination': (boolean, False),
        'EbsOptimized': (boolean, False),

By doing this, No IDLE can predict what properties the class has, in another word, auto hint and auto completion will not work.

If you look at sqlalchemy, attrs, marshmallow or WtfForm, you will see that you should use MetaClass to implement that, here's the example, then the IDLE can tell users about it.

class Instance(object):
    Affinity = Property(...)
    AvailabilityZone = Property(...)

Have you ever thinking of refactor it with the better design?

MacHu-GWU avatar Jun 28 '19 19:06 MacHu-GWU

@markpeek

I write a library https://github.com/MacHu-GWU/troposphere_mate-project on top of troposphere, it provides 100% API Compatible with troposphere, but enables Auto-Properties Hint.

Appreciate your effort on this project, it is really a great project to save me big amount of time on cloudformation.

MacHu-GWU avatar Jul 08 '19 01:07 MacHu-GWU