This repository has been archived by the owner on Dec 30, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-vpc-haproxy-blueprint.yaml
421 lines (356 loc) · 13.2 KB
/
aws-vpc-haproxy-blueprint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
tosca_definitions_version: cloudify_dsl_1_3
description: >
This Blueprint installs the nodecellar application
on an amazon ec2 cloud environment.
imports:
- http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
- http://www.getcloudify.org/spec/aws-plugin/1.4.3/plugin.yaml
- http://www.getcloudify.org/spec/diamond-plugin/1.3.4/plugin.yaml
- types/nodecellar.yaml
- types/aws-vpc-types.yaml
- types/haproxy/haproxy.yaml
- types/scale/scale.yaml
#####################################################################################
# inputs section allows the user to use same
# blueprint for creating different deployments, each one
# with its own parameters.
# to specify deployment inputs run:
# - cfy deployments create -b <blueprint_id> -d <deployment_id> -i inputs.json
#####################################################################################
inputs:
aws_access_key_id:
description: YOUR AWS ACCESS KEY ID
aws_secret_access_key:
description: YOUR AWS SECRET ACCESS KEY
ec2_region_name:
default: us-east-1
ec2_region_endpoint:
default: ec2.us-east-1.amazonaws.com
availability_zone:
default: us-east-1e
aws_config:
default:
aws_access_key_id: { get_input: aws_access_key_id }
aws_secret_access_key: { get_input: aws_secret_access_key }
ec2_region_name: { get_input: ec2_region_name }
ec2_region_endpoint: { get_input: ec2_region_endpoint }
vpc_id:
description: Your AWS Managers VPC.
vpc_cidr_block:
default: 172.16.0.0/16
public_subnet_id:
description: The public subnet in your VPC.
public_subnet_cidr:
default: 172.16.122.0/24
public_subnet_availability_zone:
default: { get_input: availability_zone }
private_subnet_id:
description: The private subnet in your VPC.
private_subnet_cidr:
default: 172.16.123.0/24
private_subnet_availability_zone:
default: { get_input: availability_zone }
key_name:
default: nodecellar
private_key_path:
default: ~/.ssh/nodecellar.pem
ami_image_id:
description: >
An AWS AMI. Tested with a Ubuntu 14.04 image.
instance_type:
description: >
The AWS instance_type. Tested with m3.medium, although that is unnecessarily large.
default: t2.micro
agent_user:
description: >
The username of the agent running on the instance created from the image.
default: ubuntu
node_templates:
nodecellar:
type: nodecellar.nodes.NodecellarApplicationModule
relationships:
################################
# Setting the mongo connection
################################
- type: node_connected_to_mongo
target: mongod
################################
# Setting the nodejs connection
################################
- type: node_contained_in_nodejs
target: nodejs
################################
# Setting the haproxy connection
################################
- type: app_connected_to_haproxy
target: haproxy
mongod:
type: nodecellar.nodes.MonitoredMongoDatabase
relationships:
- type: cloudify.relationships.contained_in
target: mongod_host
nodejs:
type: nodecellar.nodes.NodeJSServer
relationships:
- type: cloudify.relationships.contained_in
target: nodejs_host
########################################
# Note: only ubuntu haproxy installation
# is supported.
########################################
haproxy:
type: nodecellar.nodes.MonitoredHAProxy
properties:
backend_app_port: { get_property: [ nodecellar, port ] }
relationships:
- target: haproxy_frontend_host
type: cloudify.relationships.contained_in
mongod_host:
type: nodecellar.nodes.MonitoredServer
properties:
parameters:
placement: { get_property: [ private_subnet, availability_zone ] }
relationships:
###########################################################
# Attaching the mongo security group to the mongo host
###########################################################
- type: cloudify.aws.relationships.instance_connected_to_security_group
target: mongod_security_group
- type: cloudify.aws.relationships.instance_contained_in_subnet
target: private_subnet
- type: cloudify.aws.relationships.instance_connected_to_keypair
target: key
nodejs_host:
type: nodecellar.nodes.MonitoredServer
###########################################################
# Setting the nodejs_host initial number of instances to 2.
# The default values for instances.deploy is 1.
###########################################################
instances:
deploy: 2
properties:
parameters:
placement: { get_property: [ private_subnet, availability_zone ] }
relationships:
###########################################################
# Attaching the nodecellar security group to the nodejs host
###########################################################
- type: cloudify.aws.relationships.instance_connected_to_security_group
target: nodecellar_security_group
- type: cloudify.aws.relationships.instance_contained_in_subnet
target: private_subnet
- type: cloudify.aws.relationships.instance_connected_to_keypair
target: key
haproxy_frontend_host:
type: nodecellar.nodes.MonitoredServer
relationships:
###########################################################
# Attaching an ip to the haproxy frontend host
###########################################################
- type: cloudify.aws.relationships.instance_connected_to_elastic_ip
target: nodecellar_ip
###########################################################
# Attaching the haproxy frontend security group to
# the haproxy frontend host
###########################################################
- type: cloudify.aws.relationships.instance_connected_to_security_group
target: haproxy_frontend_security_group
- type: cloudify.aws.relationships.instance_contained_in_subnet
target: public_subnet
- type: cloudify.aws.relationships.instance_connected_to_keypair
target: key
###########################################################
# A security group to enable access to the mongo host
# using the port of the mongo node.
#
# We need this so that the nodecellar application can
# comminicate with MongoDB, since they are running on
# different hosts.
###########################################################
mongod_security_group:
type: cloudify.aws.nodes.SecurityGroup
properties:
aws_config: { get_input: aws_config }
description: Security Group for Mongo VMs
rules:
- ip_protocol: tcp
from_port: 22
to_port: 22
cidr_ip: { get_input: vpc_cidr_block }
- ip_protocol: tcp
from_port: { get_property: [ mongod, port ] }
to_port: { get_property: [ mongod, port ] }
cidr_ip: 0.0.0.0/0
- ip_protocol: tcp
from_port: 28017
to_port: 28017
cidr_ip: 0.0.0.0/0
relationships:
- type: cloudify.aws.relationships.security_group_contained_in_vpc
target: vpc
###########################################################
# A security group to enable access to the nodejs host
# using the port of the nodejs node.
#
# We need this so that the nodecellar application can
# receive web traffic.
###########################################################
nodecellar_security_group:
type: cloudify.aws.nodes.SecurityGroup
properties:
aws_config: { get_input: aws_config }
description: Security Group for Nodecellar VMs
rules:
- ip_protocol: tcp
from_port: 22
to_port: 22
cidr_ip: { get_input: vpc_cidr_block }
- ip_protocol: tcp
from_port: { get_property: [ nodecellar, port ] }
to_port: { get_property: [ nodecellar, port ] }
cidr_ip: 0.0.0.0/0
relationships:
- type: cloudify.aws.relationships.security_group_contained_in_vpc
target: vpc
###########################################################
# A security group to enable access to the haproxy frontend
# host using the haproxy frontend_port property.
# In addition, we open the statistics port (9000) of haproxy
#
# This security group will be attached to the
# haproxy_frontend_host
###########################################################
haproxy_frontend_security_group:
type: cloudify.aws.nodes.SecurityGroup
properties:
aws_config: { get_input: aws_config }
description: Security Group for HAProxy VM
rules:
- ip_protocol: tcp
from_port: 22
to_port: 22
cidr_ip: { get_input: vpc_cidr_block }
- ip_protocol: tcp
from_port: { get_property: [ haproxy, frontend_port ] }
to_port: { get_property: [ haproxy, frontend_port ] }
cidr_ip: 0.0.0.0/0
- ip_protocol: tcp
from_port: { get_property: [ haproxy, statistics_port ]}
to_port: { get_property: [ haproxy, statistics_port ]}
cidr_ip: 0.0.0.0/0
relationships:
- type: cloudify.aws.relationships.security_group_contained_in_vpc
target: vpc
###########################################################
# An ip to be attached to the nodejs host, since
# eventually we want to be able to access it
# from any machine, on any network.
###########################################################
nodecellar_ip:
type: cloudify.aws.nodes.ElasticIP
properties:
aws_config: { get_input: aws_config }
domain: vpc
public_subnet:
type: cloudify.aws.nodes.Subnet
properties:
aws_config: { get_input: aws_config }
use_external_resource: true
resource_id: { get_input: public_subnet_id }
cidr_block: { get_input: public_subnet_cidr }
availability_zone: { get_input: public_subnet_availability_zone }
relationships:
- type: cloudify.aws.relationships.subnet_contained_in_vpc
target: vpc
private_subnet:
type: cloudify.aws.nodes.Subnet
properties:
aws_config: { get_input: aws_config }
use_external_resource: true
resource_id: { get_input: private_subnet_id }
cidr_block: { get_input: private_subnet_cidr }
availability_zone: { get_input: private_subnet_availability_zone }
relationships:
- type: cloudify.aws.relationships.subnet_contained_in_vpc
target: vpc
vpc:
type: cloudify.aws.nodes.VPC
properties:
aws_config: { get_input: aws_config }
use_external_resource: true
resource_id: { get_input: vpc_id }
cidr_block: { get_input: vpc_cidr_block }
key:
type: cloudify.aws.nodes.KeyPair
properties:
aws_config: { get_input: aws_config }
resource_id: { get_input: key_name }
private_key_path: { get_input: private_key_path }
###########################################################
# This outputs section exposes the application endpoint.
# You can access it by running:
# - cfy deployments -d <deployment_id> outputs
###########################################################
outputs:
endpoint:
description: Web application endpoint
value:
ip_address: { get_attribute: [ nodecellar_ip, aws_resource_id ] }
port: { get_property: [ haproxy, frontend_port ] }
groups:
scale_up_group:
members: [nodejs_host]
policies:
auto_scale_up:
type: scale_policy_type
properties:
policy_operates_on_group: true
scale_limit: 6
scale_direction: '<'
scale_threshold: 3
service_selector: .*nodejs_host.*.process.node.cpu.percent
cooldown_time: 60
triggers:
execute_scale_workflow:
type: cloudify.policies.triggers.execute_workflow
parameters:
workflow: scale
workflow_parameters:
delta: 1
scalable_entity_name: nodejs_host
scale_down_group:
members: [nodejs_host]
policies:
auto_scale_down:
type: scale_policy_type
properties:
scale_limit: 2
scale_direction: '>'
scale_threshold: 1
service_selector: .*nodejs_host.*.process.node.cpu.percent
cooldown_time: 60
triggers:
execute_scale_workflow:
type: cloudify.policies.triggers.execute_workflow
parameters:
workflow: scale
workflow_parameters:
delta: -1
scalable_entity_name: nodejs_host
heal_group:
members: [nodejs_host]
policies:
simple_autoheal_policy:
type: cloudify.policies.types.host_failure
properties:
service:
- .*nodejs_host.*.cpu.total.system
interval_between_workflows: 60
triggers:
auto_heal_trigger:
type: cloudify.policies.triggers.execute_workflow
parameters:
workflow: heal
workflow_parameters:
node_instance_id: { 'get_property': [ SELF, node_id ] }
diagnose_value: { 'get_property': [ SELF, diagnose ] }