signifyd/chef-agent — pull request #18 by cwjohnston (2014-11-01 23:17:13+00:00)
Title: Separate Platform application and ELB stacks

This change set splits the `platform` CloudFormation template into application server and ELB templates. As such, the `platform` template now prompts for information about the ELB its autoscaling group should associate with.

Using the knife-cloudformation `--apply-stack` flag allows an ELB stack provisioned via the new `platform-elb` template to provide its outputs as inputs for one or more application stacks. For example:

First I create an ELB stack named `platform-test-elb`:
```shell
be knife cloudformation create platform-test-elb --file cloudformation/platform-elb.rb --defaults --poll
Cloud Formation: create
-> Name: platform-test-elb
Cloud Formation Events for Stack: platform-test-elb
Events for stack: platform-test-elb
Event Time Logical Resource Id Resource Status Resource Status Reason
2014-11-01 22:59:24 UTC platform-test-elb CREATE_IN_PROGRESS User Initiated
2014-11-01 22:59:27 UTC PlatformElb CREATE_IN_PROGRESS
2014-11-01 22:59:28 UTC PlatformElb CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 22:59:30 UTC PlatformElb CREATE_COMPLETE
2014-11-01 22:59:32 UTC PlatformElbSecurityGroup CREATE_IN_PROGRESS
2014-11-01 22:59:48 UTC PlatformElbSecurityGroup CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 22:59:49 UTC PlatformElbSecurityGroup CREATE_COMPLETE
2014-11-01 22:59:51 UTC platform-test-elb CREATE_COMPLETE
Stack create complete: SUCCESS
Outputs for stack: platform-test-elb
Elb Dns: platform-Platform-1BER95G29U8W3-504579021.us-east-1.elb.amazonaws.com
Elb Name: platform-Platform-1BER95G29U8W3
Elb Security Group: platform-test-elb-PlatformElbSecurityGroup-C145PAPY2ZRY
Environment: test
```
Using the value of the 'ELB Name' output to query for associated instances, we'll see there's nothing up my sleeve:
```
$ aws elb describe-load-balancers --load-balancer-names platform-Platform-1BER95G29U8W3 | jq '.LoadBalancerDescriptions[].Instances'
[]
```

Next I build another stack, using the `--apply-stack platform-test-elb` flag. This allows the outputs of the ELB stack can be used as input values for parameters of the same name (i.e. Elb Name and Elb Security Group) in the stack I am creating:

```shell
$ be knife cloudformation create platform-test-635 --file cloudformation/platform.rb -p PlatformBuildNumber:635 -p PlatformMinNodes:1 -p PlatformMaxNodes:1 --apply-stack platform-test-elb --defaults
Cloud Formation: create
-> Name: platform-test-635
Cloud Formation Events for Stack: platform-test-635
Events for stack: platform-test-635
Event Time Logical Resource Id Resource Status Resource Status Reason
2014-11-01 23:02:36 UTC platform-test-635 CREATE_IN_PROGRESS User Initiated
2014-11-01 23:02:41 UTC PlatformLaunchWaitHandle CREATE_IN_PROGRESS
2014-11-01 23:02:41 UTC PlatformSecurityGroup CREATE_IN_PROGRESS
2014-11-01 23:02:42 UTC PlatformElbReadyWaitHandle CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:02:42 UTC CfnUser CREATE_IN_PROGRESS
2014-11-01 23:02:42 UTC PlatformLaunchWaitHandle CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:02:42 UTC PlatformElbReadyWaitHandle CREATE_IN_PROGRESS
2014-11-01 23:02:42 UTC CfnUser CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:02:43 UTC PlatformLaunchWaitHandle CREATE_COMPLETE
2014-11-01 23:02:43 UTC PlatformElbReadyWaitHandle CREATE_COMPLETE
2014-11-01 23:02:43 UTC CfnUser CREATE_COMPLETE
2014-11-01 23:02:45 UTC CfnKeys CREATE_IN_PROGRESS
2014-11-01 23:02:46 UTC CfnKeys CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:02:47 UTC CfnKeys CREATE_COMPLETE
2014-11-01 23:02:58 UTC PlatformSecurityGroup CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:02:59 UTC PlatformSecurityGroup CREATE_COMPLETE
2014-11-01 23:03:01 UTC PlatformLaunchConfiguration CREATE_IN_PROGRESS
2014-11-01 23:03:02 UTC PlatformLaunchConfiguration CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:03:02 UTC PlatformLaunchConfiguration CREATE_COMPLETE
2014-11-01 23:03:04 UTC PlatformAutoScalingGroup CREATE_IN_PROGRESS
2014-11-01 23:03:05 UTC PlatformAutoScalingGroup CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:03:59 UTC PlatformAutoScalingGroup CREATE_COMPLETE
2014-11-01 23:04:01 UTC PlatformElbWait CREATE_IN_PROGRESS
2014-11-01 23:04:01 UTC PlatformLaunchWaitCondition CREATE_IN_PROGRESS
2014-11-01 23:04:02 UTC PlatformElbWait CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:04:02 UTC PlatformLaunchWaitCondition CREATE_IN_PROGRESS Resource creation Initiated
2014-11-01 23:09:58 UTC PlatformLaunchWaitCondition CREATE_COMPLETE
2014-11-01 23:09:58 UTC PlatformElbWait CREATE_COMPLETE
2014-11-01 23:10:01 UTC platform-test-635 CREATE_COMPLETE
```

Now the one instance in my auto-scaling group is registered with the ELB:
```
$ aws elb describe-load-balancers --load-balancer-names platform-Platform-1BER95G29U8W3 | jq '.LoadBalancerDescriptions[].Instances'
[
{
"InstanceId": "i-40e155aa"
}
]
```

Tada! :tada: