-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Tags types seems a bit confusing for newcomers #2268
Comments
Most of the resource Tags take the first form where you can create a Tags object and it will output the correct array of Tag. The "object" or Json Tags were introduced at some point into CloudFormation and troposphere validates those against a dict. In both cases you can start with creating a dict with the key/value pairs and, in the case of the first form use:
and in the second case (such as JobDefinition) use:
Give this a try and let me know how it goes. I'll also note there are autoscaling Tags that have an additional PropagateAtLaunch key. |
Thanks @markpeek for your insights. Nevertheless, I was expecting troposphere to report that I was using the wrong type during the template construction but it did not when I passed an instance of the Is this the expected behavior? |
Thank you for the addition context. I just created PR #2270 which should provide better validation and trigger an error if you pass a Tags object to a Json variant of Tags. Feel free to review, test, and approve. |
Hello @markpeek, I have just tested your branch with my originally failing code and now troposphere reports the error 🙂: TypeError: <class 'troposphere.batch.JobDefinition'>: JobDefinition.Tags is <class 'troposphere.Tags'>, expected <class 'dict'> Also tested with a Thank you for such a fast fix which is also unit tested 👍. |
@gautaz thank you for the issue and for validating the patch. Always great to have fresh eyes on pain points like this one. |
You're welcome, troposphere is amazing! |
Hello,
Looking at the current CloudFormation resource provider schemas, tags properties are mainly expressed in 2 different types (
array
orobject
):AWS::EC2::Instance:
AWS::Batch::JobDefinition:
The situation is quite confusing for a newcomer, in particular regarding the
Tags
class provided by troposphere.This class seems to generate the
array
type of tags.At first I used an instance of the
Tags
class to add tags to a JobDefinition which was bound to fail, is there any way to ensure that troposphere will raise an error in this case?Are there any best practices or recommendations regarding the usage of the
Tags
class?Is using a Python dictionary to express the current
object
type of tags the way to go (for instance for a JobDefinition)?The text was updated successfully, but these errors were encountered: