Skip to content
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

Add AutoScaling Example With Scaling Rules and Notifications #459

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

rcuza
Copy link
Contributor

@rcuza rcuza commented Apr 11, 2016

This pull requests creates an example troposphere script that creates the AutoScalingMultiAZWithNotifications.template.

In order to create a comment that was in the example CloudFormation template, I added a Comment class to troposphere/cloudformation.py. I am not sure if this is the right place. I was able to create the template when I added the same class to troposphere/__init__.py. I did not ultimately choose that location because I do not know if the Comment property is universal to all resources in CloudFormation templates.

Perhaps I should of done with the Comment property what I had to do with the NotificationConfigurations property in the AutoScalingGroup resource, namely edit the template to match the troposphere code. I could not create the NotificationConfigurations without passing it a list, which is supported by the AWS AutoScalingGroup documentation.

@rcuza
Copy link
Contributor Author

rcuza commented Apr 11, 2016

To make it easier to see how I changed the original Amazon template, here is the diff:

(troposphere) $ cat tests/examples_output/AutoScalingMultiAZWithNotifications-orig.template | python -m json.tool  > tests/examples_output/AutoScalingMultiAZWithNotifications-orig-sorted.template
(troposphere) $ diff tests/examples_output/AutoScalingMultiAZWithNotifications-orig-sorted.template tests/examples_output/AutoScalingMultiAZWithNotifications.template
833,841c833,843
<                 "NotificationConfiguration": {
<                     "NotificationTypes": [
<                         "autoscaling:EC2_INSTANCE_LAUNCH",
<                         "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
<                         "autoscaling:EC2_INSTANCE_TERMINATE",
<                         "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
<                     ],
<                     "TopicARN": {
<                         "Ref": "NotificationTopic"
---
>                 "NotificationConfigurations": [
>                     {
>                         "NotificationTypes": [
>                             "autoscaling:EC2_INSTANCE_LAUNCH",
>                             "autoscaling:EC2_INSTANCE_LAUNCH_ERROR",
>                             "autoscaling:EC2_INSTANCE_TERMINATE",
>                             "autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
>                         ],
>                         "TopicARN": {
>                             "Ref": "NotificationTopic"
>                         }
843c845
<                 }
---
>                 ]

@markpeek
Copy link
Member

I like the example and think it is good to add it. The issue I'm wrestling with is whether adding Comment would lead to confusion since it will only work in a Metadata attribute and people might try using it in other objects. Let me ponder this one for a bit more.

@rcuza
Copy link
Contributor Author

rcuza commented Apr 20, 2016

It looks like Metadata is an attribute for every resource (ref: Adding Comments inside AWS CloudFormation Templates and AWS Metadata Attribute doc). Metadata is a valid key at the top of a CF template, too.

As you pointed out, every Metadata attribute can have a Comment key, but Comment is not a attribute for every resource. What is the best way to put Comment inside of Metadata?

When I search the troposphere code base I find Metadata in __init__.py, autoscaling.py, and cloudformation.py. For the latter two the Metadata class is based on the AWSHelperFn class. For __init__.py, Metadata is just listed as an attribute. Why is there this difference? My first stab at the answer is that while all resources have a Metadata attribute, each resource has different keys within that it expects. A map resource with a Metadata attribute will not be able to do anything with a "AWS::CloudFormation::Init" key, but a LaunchConfig resource will be able to use it.

Instead of __init__.py declaring Metadata as a simple attribute of every BaseAWSObject, maybe it should be a class that could be extended for each resource if it needs it. The Comment key can be a method of this class or just an attribute. I'm not sure which would be easier to validate or more intuitive to use. Does this accomplish our goal? (yes, I am asking before I actually tried coding it. 🙀)

@markpeek
Copy link
Member

As you pointed out Metadata is in some of the existing objects. I'll have to spend some time looking at git history to try to figure out why/when those were added. This is sometimes difficult given the lack of historical docs. Given that Metadata is really just a json blob we could remove Comment and just attach and arbitrary dict instead. Or just leave Comment as-is in your PR and see what happens. I'm leaning towards the latter but still thinking about it. I understand your comment about adding Metadata to every BaseAWSObject but wondering if the complexity is worth it for this issue.

@rcuza
Copy link
Contributor Author

rcuza commented Apr 20, 2016

I tried adding the Comment using a variety of formats around commit 7a8026d, but it wouldn't build or pass tests (I can't remember which).

Whichever way you decide, let me know and I can adjust the PR. I might try a POC for making Metadata more robust.

@rcuza
Copy link
Contributor Author

rcuza commented Apr 22, 2016

Doing some digging I found the following issues related to Metadata:

Unfortunately, this exercise did not give me an opinion on which way to move forward. I'm sharing the links as it may be useful to you.

@rcuza
Copy link
Contributor Author

rcuza commented May 15, 2018

Is this PR still relevant? If not, I'll close it out.

rcuza added 8 commits May 15, 2018 15:24
The AWS example template as a Comment key in the
Metadata of the cloudformation template. I added a Comment
class to create this object.
According to the Cloudformation documentation,
"AWS::AutoScaling::AutoScalingGroup" types have
a property "NotificationConfigurations" that is
a list. The original template has the singular
and it isn't a list. Troposphere wouldn't build
the template using this property.
Adjust line lengths to match 79 character
preference
@rcuza
Copy link
Contributor Author

rcuza commented May 15, 2018

The failure is in

FAIL: test_template_generator (tests.test_examples_template_generator.test_AutoScalingMultiAZWithNotifications)

If there is any interest in this let me know and I'll figure out how to update the tests to match the current code base. Otherwise I'll just close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants