cloudtools / cloudtools/troposphere

Template.add_resource should only allow resources

Open
#956 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
4.9k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

`Template.add_resource` really should only allow an object of AWSObject to be added - right now this is caught by this line of code https://github.com/cloudtools/troposphere/blob/master/troposphere/__init__.py#L565

but not well - and it's mostly a side effect. It results in a hard to understand exception as well:

`AttributeError: 'dict' object has no attribute 'title'`

This all came up because a new user of stacker was trying to call `add_resource` in a blueprint on an `AWSProperty` instance. I figure there's some room here for better error handling.

I started a PR on this, but ran into issues because `cloudformation.AWSCustomObject` is not a subclass of `AWSObject`. Changing it to a subclass of `AWSObject` resulted in this test failing since it loads every class that is a subclass of `AWSObject`: https://github.com/cloudtools/troposphere/blob/master/tests/test_int_type.py

I'll probably try to dive back into this later, but wanted to open this in case anyone else has any ideas on what the right way to fix this is.

Contributor guide

Open the contributing guide

Research direction

Start in troposphere/__init__.py around line 565 and inspect Template.add_resource, AWSObject, AWSCustomObject, and AWSProperty. Then read tests/test_int_type.py, which loads subclasses of AWSObject and currently fails when AWSCustomObject is changed. Done means invalid resources produce a clear error without breaking the existing type tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.