-
Notifications
You must be signed in to change notification settings - Fork 0
/
wso2-product-deployer-template.yml
516 lines (505 loc) · 14.9 KB
/
wso2-product-deployer-template.yml
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
AWSTemplateFormatVersion: 2010-09-09
##############################################################################################
# Mappings for Ubuntu AMIs
# Refer https://cloud-images.ubuntu.com/locator/ec2/ for ubuntu AMI-ID's for the LTS version
##############################################################################################
Mappings:
RegionMap:
ap-northeast-1:
AMI: ami-15872773
ap-northeast-2:
AMI: ami-7b1cb915
ap-south-1:
AMI: ami-bc0d40d3
ap-southeast-1:
AMI: ami-67a6e604
ap-southeast-2:
AMI: ami-41c12e23
ca-central-1:
AMI: ami-8a71c9ee
eu-central-1:
AMI: ami-97e953f8
eu-west-1:
AMI: ami-add175d4
eu-west-2:
AMI: ami-ecbea388
sa-east-1:
AMI: ami-466b132a
us-east-1:
AMI: ami-da05a4a0
us-east-2:
AMI: ami-336b4456
us-west-1:
AMI: ami-1c1d217c
us-west-2:
AMI: ami-0a00ce72
#############################
# User inputs
#############################
Parameters:
WUMUserName:
Type: String
Default: ""
Description: Enter WUM user name
WUMPassword:
Type: String
Default: ""
NoEcho: true
Description: Enter WUM user password to get the updated WSO2 products deployed. If not provided standard released pack will be deployed
EC2KeyPair:
Description: This is used to ssh to the node. If you don't have a key, please create one from AWS console and rerun the script
Type: "AWS::EC2::KeyPair::KeyName"
InstanceType:
Description: EC2 instance type [t2.micro is the free tier]
Type: String
Default: t2.micro
AllowedValues:
- t2.nano
- t1.micro
- t2.micro
- t2.small
- t2.medium
- t2.large
- t2.xlarge
- t2.2xlarge
- m3.medium
- m3.large
- m3.xlarge
- m3.2xlarge
ConstraintDescription: must be a valid EC2 instance type.
InstanceUserName:
Type: String
Default: ubuntu
Description: Username of the EC2 instance user.
DeploymentType:
Type: String
Default: NodesWithoutProducts
AllowedValues:
- OneNodeEI6.1.1-Deployment
- OneNodeAPIM-2.1.0-Deployment
- NodesWithoutProducts
UseRDS:
Type: String
Default: No
AllowedValues:
- Yes
- No
ConstraintDescription: Must specify whether to use an external RDS instance or not
Description: Use RDS instance as an external DB for the nodes.
RDSUsername:
Type: String
Default: root
ConstraintDescription: Must specify username for the RDS admin user
Description: RDS instance admin username.
RDSPassword:
Type: String
NoEcho: true
Default: root1234
ConstraintDescription: Must specify password for the RDS admin user
Description: RDS instance admin user password [Default set to "root1234"].
Conditions:
CreateRDSResource: !Equals [ !Ref UseRDS, Yes ]
################################
# Create AWS resources
################################
Resources:
##############################
# Create VPC and subnets
##############################
WSO2EnvVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: 10.0.0.0/16
InstanceTenancy: default
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: Name
Value: ei-vpc
WSO2EnvPrivateSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select
- '0'
- !GetAZs ''
VpcId: !Ref WSO2EnvVPC
Tags:
- Key: Name
Value: ei-private-subnet-1
WSO2EnvPublicSubnet1:
Type: 'AWS::EC2::Subnet'
Properties:
CidrBlock: 10.0.0.0/24
AvailabilityZone: !Select
- '0'
- !GetAZs ''
VpcId: !Ref WSO2EnvVPC
Tags:
- Key: Name
Value: ei-public-subnet-1
WSO2EnvPublicSubnet2:
Type: 'AWS::EC2::Subnet'
Properties:
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select
- '1'
- !GetAZs ''
VpcId: !Ref WSO2EnvVPC
Tags:
- Key: Name
Value: ei-public-subnet-2
WSO2EnvInternetGateway:
Type: 'AWS::EC2::InternetGateway'
Properties: {}
WSO2EnvDHCPOptions:
Type: 'AWS::EC2::DHCPOptions'
Properties:
DomainNameServers:
- AmazonProvidedDNS
WSO2EnvNetworkAcl:
Type: 'AWS::EC2::NetworkAcl'
Properties:
VpcId: !Ref WSO2EnvVPC
WSO2EnvPublicRouteTable1:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref WSO2EnvVPC
WSO2EnvRouteTable2:
Type: 'AWS::EC2::RouteTable'
Properties:
VpcId: !Ref WSO2EnvVPC
WSO2EnvBastionEIPAssociation:
Type: 'AWS::EC2::EIPAssociation'
Properties:
AllocationId: !GetAtt WSO2EnvBastionEIP.AllocationId
InstanceId: !Ref WSO2EnvBastionNode
################################
# Create network configurations
################################
WSO2EnvNATGateway:
DependsOn: gw1
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt WSO2EnvEIP1.AllocationId
SubnetId: !Ref WSO2EnvPublicSubnet1
Tags:
- Key: Name
Value: WSO2EnvNatGateway
acl1:
Type: 'AWS::EC2::NetworkAclEntry'
Properties:
CidrBlock: 0.0.0.0/0
Egress: 'true'
Protocol: '-1'
RuleAction: allow
RuleNumber: '100'
NetworkAclId: !Ref WSO2EnvNetworkAcl
acl2:
Type: 'AWS::EC2::NetworkAclEntry'
Properties:
CidrBlock: 0.0.0.0/0
Protocol: '-1'
RuleAction: allow
RuleNumber: '100'
NetworkAclId: !Ref WSO2EnvNetworkAcl
subnetacl1:
Type: 'AWS::EC2::SubnetNetworkAclAssociation'
Properties:
NetworkAclId: !Ref WSO2EnvNetworkAcl
SubnetId: !Ref WSO2EnvPrivateSubnet1
subnetacl2:
Type: 'AWS::EC2::SubnetNetworkAclAssociation'
Properties:
NetworkAclId: !Ref WSO2EnvNetworkAcl
SubnetId: !Ref WSO2EnvPublicSubnet1
gw1:
Type: 'AWS::EC2::VPCGatewayAttachment'
Properties:
VpcId: !Ref WSO2EnvVPC
InternetGatewayId: !Ref WSO2EnvInternetGateway
subnetroute1:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2EnvPublicRouteTable1
SubnetId: !Ref WSO2EnvPublicSubnet1
subnetroute2:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Properties:
RouteTableId: !Ref WSO2EnvRouteTable2
SubnetId: !Ref WSO2EnvPrivateSubnet1
route1:
Type: 'AWS::EC2::Route'
Properties:
DestinationCidrBlock: 0.0.0.0/0
RouteTableId: !Ref WSO2EnvPublicRouteTable1
GatewayId: !Ref WSO2EnvInternetGateway
DependsOn: gw1
route2:
Type: 'AWS::EC2::Route'
Properties:
DestinationCidrBlock: 0.0.0.0/0
RouteTableId: !Ref WSO2EnvRouteTable2
NatGatewayId: !Ref WSO2EnvNATGateway
dchpassoc1:
Type: 'AWS::EC2::VPCDHCPOptionsAssociation'
Properties:
VpcId: !Ref WSO2EnvVPC
DhcpOptionsId: !Ref WSO2EnvDHCPOptions
#########################
# Create security groups
#########################
WSO2EnvInstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: security group for EI EC2 compute instances
VpcId: !Ref WSO2EnvVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 0
ToPort: 65535
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
WSO2EnvLBSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: security group for EI EC2 compute instances
VpcId: !Ref WSO2EnvVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 9763
ToPort: 9763
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
###########################
# Create Elastic IPs
###########################
WSO2EnvBastionEIP:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
WSO2EnvEIP1:
Type: 'AWS::EC2::EIP'
Properties:
Domain: vpc
#######################
# EC2 Compute instances
#######################
WSO2EnvBastionNode:
Type: 'AWS::EC2::Instance'
Properties:
DisableApiTermination: 'false'
InstanceInitiatedShutdownBehavior: stop
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
InstanceType: t2.micro
KeyName: !Ref EC2KeyPair
Monitoring: 'false'
Tags:
- Key: Name
Value: ei-bastion-node
NetworkInterfaces:
- DeleteOnTermination: 'true'
Description: Primary network interface
DeviceIndex: 0
SubnetId: !Ref WSO2EnvPublicSubnet1
PrivateIpAddresses:
- PrivateIpAddress: 10.0.0.70
Primary: 'true'
GroupSet:
- !Ref WSO2EnvInstanceSecurityGroup
WSO2EnvMainInstance:
Type: 'AWS::EC2::Instance'
Properties:
DisableApiTermination: 'false'
InstanceInitiatedShutdownBehavior: stop
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
InstanceType: !Ref InstanceType
KeyName: !Ref EC2KeyPair
Monitoring: 'false'
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
cd /home/ubuntu/
git clone https://github.com/Asitha/aws-cloudformation-templates.git --depth 1
chown -R ubuntu aws-cloudformation-templates
cd aws-cloudformation-templates
chmod +x ./setup-instance-env.sh
chmod +x ./setup-ei6.1.1.sh
bash ./setup-instance-env.sh ${InstanceUserName} ${WUMUserName} ${WUMPassword} &> /home/ubuntu/setup-instance-env.out
if [ "${DeploymentType}" = "OneNodeEI6.1.1-Deployment" ]; then
local="local"
if [ "${UseRDS}" = "Yes" ]; then
local="useRDS"
fi
bash ./setup-ei6.1.1.sh ${InstanceUserName} $local ${WSO2EnvDBInstance.Endpoint.Address} ${WSO2EnvDBInstance.Endpoint.Port} ${RDSUsername} ${RDSPassword} &> /home/ubuntu/setup-ei-env.out
fi
Tags:
- Key: Name
Value: ei-instance1
NetworkInterfaces:
- DeleteOnTermination: 'true'
Description: Primary network interface
DeviceIndex: 0
SubnetId: !Ref WSO2EnvPrivateSubnet1
PrivateIpAddresses:
- PrivateIpAddress: 10.0.1.71
Primary: 'true'
GroupSet:
- !Ref WSO2EnvInstanceSecurityGroup
WSO2EnvAnalyticsInstance:
Type: 'AWS::EC2::Instance'
Properties:
DisableApiTermination: 'false'
InstanceInitiatedShutdownBehavior: stop
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", AMI]
InstanceType: t2.micro
KeyName: !Ref EC2KeyPair
Monitoring: 'false'
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
cd /home/ubuntu/
git clone https://github.com/Asitha/aws-cloudformation-templates.git --depth 1
chown -R ubuntu aws-cloudformation-templates
cd aws-cloudformation-templates
chmod +x ./setup-instance-env.sh
chmod +x ./setup-ei6.1.1.sh
bash ./setup-instance-env.sh ubuntu ${WUMUserName} ${WUMPassword} &> /home/ubuntu/setup-instance-env.out
Tags:
- Key: Name
Value: ei-analytics-instance
NetworkInterfaces:
- DeleteOnTermination: 'true'
Description: Primary network interface
DeviceIndex: 0
SubnetId: !Ref WSO2EnvPrivateSubnet1
PrivateIpAddresses:
- PrivateIpAddress: 10.0.1.72
Primary: 'true'
GroupSet:
- !Ref WSO2EnvInstanceSecurityGroup
#######################
# Create RDS instances
#######################
WSO2EnvDBInstance:
Type: AWS::RDS::DBInstance
Properties:
AllocatedStorage: 20
DBInstanceClass: db.t2.micro
Engine: MySQL
DBInstanceIdentifier: wso2-ei-dbinstance
MasterUsername: root
MasterUserPassword: root1234
AutoMinorVersionUpgrade: false
BackupRetentionPeriod: 0
DBSubnetGroupName: !Ref WSO2EnvDBSubnetGroup
VPCSecurityGroups:
- !Ref WSO2EnvDBSecurityGroup
AvailabilityZone: !Select
- '0'
- !GetAZs ''
DeletionPolicy: Snapshot
WSO2EnvDBSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: RDS subnet group
SubnetIds:
- !Ref WSO2EnvPublicSubnet1
- !Ref WSO2EnvPublicSubnet2
- !Ref WSO2EnvPrivateSubnet1
WSO2EnvDBSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Security group for EI RDS
VpcId: !Ref WSO2EnvVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
########################
# Create Load Balancers
########################
WSO2EnvAxis28280ALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref WSO2EnvAxis28280LBTargetGroup
LoadBalancerArn: !Ref WSO2EnvAxis28280ApplicationLoadBalancer
Port: 8080
Protocol: HTTP
WSO2EnvAxis28280ApplicationLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
Subnets:
- !Ref WSO2EnvPublicSubnet1
- !Ref WSO2EnvPublicSubnet2
SecurityGroups:
- !Ref WSO2EnvLBSecurityGroup
WSO2EnvAxis28280LBTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 4
HealthCheckPath: /services/Version
HealthCheckPort: 8280
Matcher:
HttpCode: 200
Name: ei-axis2-8280
Port: 8280
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: '20'
Targets:
- Id: !Ref WSO2EnvMainInstance
Port: 8280
UnhealthyThresholdCount: 3
VpcId:
Ref: WSO2EnvVPC
Tags:
- Key: Name
Value: ei-axis2-8280
#####################################
# Print details of the created stack
#####################################
Description: Creates a VPC with two subnets for EI
Outputs:
DatabaseURL:
Value: !Sub '${WSO2EnvDBInstance.Endpoint.Address}:${WSO2EnvDBInstance.Endpoint.Port}'
Description: "MySQL database url"
BastionEIP:
Value: !Sub '${WSO2EnvBastionNode.PublicIp}'
Description: Elastic IP for the Bastion node
EIELB:
Value: !Join
- ''
- - 'http://'
- !GetAtt
- WSO2EnvAxis28280ApplicationLoadBalancer
- DNSName