-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrdb_cloudformation_template.yaml
2445 lines (2428 loc) · 156 KB
/
crdb_cloudformation_template.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
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Description: Create a VPC, Internet Gateway, Subnets, Route Tables, Security Groups and EC2 Instances running the Cockroach Database
AWSTemplateFormatVersion: '2010-09-09'
#
# ToDo:
# Cluster Name
#
# MyIP 72.132.195.192
# Creating a security group that references itself
# https://gist.github.com/alanwill/9254414
#
# Using parameters
# https://curiousorbit.com/blog/cloudformation-using-parameters/
#
# AWS Parameters
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
#
# AWS Subnet Configuration
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
#
# AWS Route Table Configuration
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-routetable.html
#
# AWS Routes Configuration
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-route.html
Mappings:
amazonLinuxAmi:
us-east-1:
AMI: ami-0cff7528ff583bf9a
# AMI: ami-0ed9277fb7eb570c9
us-east-2:
AMI: ami-0568773882d492fc8
# AMI: ami-002068ed284fb165b
us-west-1:
AMI: ami-03af6a70ccd8cb578
us-west-2:
AMI: ami-098e42ae54c764c35
# AMI: ami-00f7e5c52c0f43726
ap-southeast-1:
AMI: ami-0c802847a7dd848c0
Parameters:
VpcCidrParameter:
Description: "CIDR Block For the VPC"
Type: String
Default: "10.173.12.0/24"
VpcNamePrefix:
Description: "VPC Name Prefix. The name will be the prefix plus the region name. Ex: vpc01-us-west-2"
Type: String
Default: "vpc01"
# See the following function which splits the /24 CIDR range into 6 CIDRs with a subnet mask "/27"
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-cidr.html
VpcAzs:
Type: List<AWS::EC2::AvailabilityZone::Name>
Description: "Comma-delimited list of three AZs"
Default: "us-west-2a,us-west-2b,us-west-2c"
CockroachVersion:
Type: String
Default: "22.2.5"
Description: Cockroach Version to install
AllowedValues:
- "22.2.5"
- "22.2.4"
- "22.2.3"
- "22.2.2"
- "22.2.1"
- "22.1.14"
- "22.1.13"
- "22.1.12"
- "22.1.11"
- "22.1.10"
- "22.1.9"
- "22.1.8"
- "22.1.7"
- "22.1.6"
- "22.1.5"
- "22.1.4"
- "22.1.2"
- "22.1.0"
- "21.2.17"
- "21.2.16"
- "21.2.14"
- "21.2.13"
- "21.2.10"
- "21.2.9"
- "21.2.5"
- "21.2.4"
- "21.2.3"
- "21.1.15"
- "21.1.13"
- "20.2.18"
- "20.1.17"
- "19.2.12"
InstanceType:
Type: String
Default: m5a.large
Description: Instance type. (Allowed values are in order by increasing price range). m4.large is 2vCPU, 8GB priced as $0.1/hr.
AllowedValues:
- t2.micro
- t3a.small
- t3.small
- t3a.medium
- t3.medium
- t3a.large
- c5a.large
- t3.large
- c5.large
- c6i.large
- c5ad.large
- m5a.large
- m6a.large
- t2.large
- c5d.large
- m5.large
- m6i.large
- c4.large
- m4.large
- m5ad.large
- c5n.large
- m5d.large
- r5a.large
- m5n.large
- r5.large
- r6i.large
- c1.medium
- r5ad.large
- m3.large
- r4.large
- m5dn.large
- r5d.large
- r5b.large
- r5n.large
- t3a.xlarge
- c5a.xlarge
- i3.large
- m5zn.large
- r3.large
- t3.xlarge
- r5dn.large
- c5.xlarge
- c6i.xlarge
- c5ad.xlarge
- c5d.2xlarge
- c5d.4xlarge
- c5d.9xlarge
- m5.xlarge
- m5.2xlarge
- m5.4xlarge
- m5.8xlarge
- m5a.xlarge
- m5a.2xlarge
- m5a.4xlarge
- m5a.8xlarge
- m6a.large
- m6a.xlarge
- m6a.2xlarge
- m6a.4xlarge
- m6a.8xlarge
- m6i.large
- m6i.xlarge
- m6i.2xlarge
- m6i.4xlarge
- m6i.8xlarge
NumberOfNodes:
Type: Number
Default: 3
AllowedValues:
- 3
- 6
- 9
VolumeType:
Type: String
Default: gp2
AllowedValues:
- gp2
- gp3
VolumeSize:
Type: Number
Description: "The size in GB of the volume you would like attached to the instance. The min is 8GB"
Default: 8
MinValue: 8
MyIP:
Type: String
Description: "Your IP address. This will be used in the security group configuration to provide SSH/RDP access to EC2 instances. A CIDR range of /32 will be appended."
Default: "0.0.0.0"
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
ConstraintDescription: must be a valid IP address of the form x.x.x.x.
KeyPairName:
Description: "Key Pair Name (specific to a region) to be used for the EC2 instances. This keypair must already exist prior to runing this CloudFormation script."
Type: "AWS::EC2::KeyPair::KeyName"
CRDBAMIID:
Description: "Amazon Linux AMI. us-east-1: ami-05fa00d4c63e32376, us-east-2: ami-0568773882d492fc8, us-west-2: ami-0c2ab3b8efb09f272, ap-southeast-1: ami-0b89f7b3f054b957e"
Type: AWS::EC2::Image::Id
Default: ami-0c2ab3b8efb09f272
ClusterName:
Description: "The name for the Cockroach Cluster"
Type: String
Default: "CRDB01"
ExistingJoinString:
Description: "If you are joining the nodes being created here to another region, use the join string created previously (see the Output section of a previously executed stack in another region). Otherwise, leave this as NONE."
Type: String
Default: NONE
RunInit:
Description: "Choosing 'YES' to this option will cuase the 'cockroach init' command to be executed when all nodes are ready. This may cause the CloudFormation process to run a little longer."
Type: String
Default: "YES"
AllowedValues:
- "YES"
- "NO"
Installpsql:
Description: "Choosing 'YES' to this option will install psql (postgresql11) on all nodes allowing you to run psql, or connect to cockroach via a URL."
Type: String
Default: "NO"
AllowedValues:
- "YES"
- "NO"
InstallHAProxy:
Description: "Choose 'YES' to this option will install an EC2 instance running HA Proxy with all the necessary configuration to connect to the Cockroach Database."
Type: String
Default: "YES"
AllowedValues:
- "YES"
- "NO"
HAProxyInstanceType:
Type: String
Default: t3.small
Description: "HA Proxy Instance type. (Only used if InstallHAProxy is 'YES')"
AllowedValues:
- t2.micro
- t3a.small
- t3.small
- t3a.medium
- t3.medium
- t3a.large
- c5a.large
- t3.large
- c5.large
- c6i.large
- c5ad.large
- m5a.large
- m6a.large
- t2.large
- c5d.large
- m5.large
- m6i.large
- c4.large
- m4.large
- m5ad.large
- c5n.large
- m5d.large
- r5a.large
- m5n.large
- r5.large
- r6i.large
- c1.medium
- r5ad.large
- m3.large
- r4.large
- m5dn.large
- r5d.large
- r5b.large
- r5n.large
- t3a.xlarge
- c5a.xlarge
- i3.large
- m5zn.large
- r3.large
- t3.xlarge
- r5dn.large
- c5.xlarge
- c6i.xlarge
- c5ad.xlarge
- c5d.2xlarge
- c5d.4xlarge
- c5d.9xlarge
- m5.xlarge
- m5.2xlarge
- m5.4xlarge
- m5.8xlarge
- m5a.xlarge
- m5a.2xlarge
- m5a.4xlarge
- m5a.8xlarge
- m6a.large
- m6a.xlarge
- m6a.2xlarge
- m6a.4xlarge
- m6a.8xlarge
- m6i.large
- m6i.xlarge
- m6i.2xlarge
- m6i.4xlarge
- m6i.8xlarge
Conditions:
UseNewJoinString: !Equals [!Ref ExistingJoinString, NONE]
InstallPostgres: !Equals [!Ref Installpsql, "YES"]
RunInitCommand: !Equals [!Ref RunInit, "YES"]
CreateHAProxy: !Equals [!Ref InstallHAProxy, "YES"]
Create6Nodes: !Or [!Equals [!Ref NumberOfNodes, 6], !Equals [!Ref NumberOfNodes, 9] ]
Create9Nodes: !Equals [!Ref NumberOfNodes, 9]
# Helpful for debugging -- change one of the "YES" values to "NO" and this will create the infrasturcture but no instances.
CreateNodes: !Equals ["YES", "YES"]
Resources:
CreateVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref "VpcCidrParameter"
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: default
Tags:
- Key: Name
Value: !Join ['-', [ !Ref 'VpcNamePrefix', !Ref 'AWS::Region']]
InternetGateway01:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Join ['-', [ "ig01", !Ref 'VpcNamePrefix', !Ref 'AWS::Region']]
VPCGatewayAttachment01:
DependsOn:
- CreateVPC
- InternetGateway01
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway01
VpcId: !Ref CreateVPC
subnet2Public:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [0, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: aza-pub-subnet2
MapPublicIpOnLaunch: true
subnet1Private:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [0, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 1, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: aza-pri-subnet1
MapPublicIpOnLaunch: false
subnet4Public:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [1, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: azb-pub-subnet4
MapPublicIpOnLaunch: True
subnet3Private:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [1, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 3, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: azb-pri-subnet3
MapPublicIpOnLaunch: false
subnet6Public:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [2, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: azc-pub-subnet6
MapPublicIpOnLaunch: True
subnet5Private:
DependsOn: CreateVPC
Type: AWS::EC2::Subnet
Properties:
# To be clear, the first line sets up the AZ, the second line substitues the AZ (a, b, c, etc) with the reference parameter value
# AvailabilityZone: !Sub
# - "${AWS::Region}${AZ}"
# - AZ: !Select [0, !Ref VpcAzs]
AvailabilityZone: !Select [2, !Ref VpcAzs]
# AvailabilityZone: "us-west-2a"
VpcId: !Ref CreateVPC
# CidrBlock: !Select [0, !Ref SubnetIpBlocks]
CidrBlock: !Select [ 5, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]]
Tags:
- Key: Name
Value: azc-pri-subnet5
MapPublicIpOnLaunch: false
routeTable01Private:
DependsOn: CreateVPC
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: rt01-private
VpcId: !Ref CreateVPC
routeTable02Public:
DependsOn: CreateVPC
Type: AWS::EC2::RouteTable
Properties:
Tags:
- Key: Name
Value: rt02-public
VpcId: !Ref CreateVPC
privateSubnetRouteAssociations1:
DependsOn:
- subnet1Private
- routeTable01Private
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet1Private
RouteTableId:
Ref: routeTable01Private
privateSubnetRouteAssociations2:
DependsOn:
- routeTable01Private
- subnet3Private
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet3Private
RouteTableId:
Ref: routeTable01Private
privateSubnetRouteAssociations3:
DependsOn:
- routeTable01Private
- subnet5Private
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet5Private
RouteTableId:
Ref: routeTable01Private
publicSubnetRouteAssociations1:
DependsOn:
- routeTable02Public
- subnet2Public
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet2Public
RouteTableId:
Ref: routeTable02Public
publicSubnetRouteAssociations2:
DependsOn:
- routeTable02Public
- subnet4Public
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet4Public
RouteTableId:
Ref: routeTable02Public
publicSubnetRouteAssociations3:
DependsOn:
- routeTable02Public
- subnet6Public
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: subnet6Public
RouteTableId:
Ref: routeTable02Public
InternetRoute:
Type: AWS::EC2::Route
DependsOn:
- VPCGatewayAttachment01
- routeTable02Public
Properties:
RouteTableId:
Ref: routeTable02Public
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: InternetGateway01
InstanceSecurityGroup01:
Type: AWS::EC2::SecurityGroup
DependsOn: CreateVPC
Properties:
Tags:
- Key: Name
Value: sg01
GroupDescription: Allow desktop access (SSH, RDP, Database, HTTP) to EC2 instances
VpcId:
Ref: CreateVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Join ['/', [ !Ref 'MyIP', '32']]
Description: "SSH"
- IpProtocol: tcp
FromPort: 3389
ToPort: 3389
CidrIp: !Join ['/', [ !Ref 'MyIP', '32']]
Description: "RDP"
- IpProtocol: tcp
FromPort: 26257
ToPort: 26257
CidrIp: !Join ['/', [ !Ref 'MyIP', '32']]
Description: "CockroachDB"
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
CidrIp: !Join ['/', [ !Ref 'MyIP', '32']]
Description: "CockroachDB UI"
InstanceSecurityGroup02:
Type: AWS::EC2::SecurityGroup
DependsOn: CreateVPC
Properties:
Tags:
- Key: Name
Value: sg02
GroupDescription: Allow http to client host
VpcId:
Ref: CreateVPC
InstanceSecurityGroup02Ingress:
Type: AWS::EC2::SecurityGroupIngress
DependsOn: InstanceSecurityGroup02
Properties:
GroupId: !Ref InstanceSecurityGroup02
IpProtocol: tcp
FromPort: 0
ToPort: 65535
SourceSecurityGroupId: !Ref InstanceSecurityGroup02
Description: "Intra Node Communication"
# ------------------------------------------------------
# Create the public IP Addresses for Each of the Nodes
# up to 9 separate IP addresses
# ENIs need to be created for all of the possible CRDB
# nodes even if they're not going to be used in case
# we want to create the HAProxy instance. This is a
# limitation of the way CloudFormation works.
# ------------------------------------------------------
CRDBIPNode01:
DependsOn:
- subnet2Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "4"
SubnetId: !Ref subnet2Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode01
CRDBIPNode02:
DependsOn:
- subnet4Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "68"
SubnetId: !Ref subnet4Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode02
CRDBIPNode03:
DependsOn:
- subnet6Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "132"
SubnetId: !Ref subnet6Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode03
CRDBIPNode04:
# Condition: Create6Nodes
DependsOn:
- subnet2Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "5"
SubnetId: !Ref subnet2Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode04
CRDBIPNode05:
# Condition: Create6Nodes
DependsOn:
- subnet4Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "69"
SubnetId: !Ref subnet4Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode05
CRDBIPNode06:
# Condition: Create6Nodes
DependsOn:
- subnet6Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "133"
SubnetId: !Ref subnet6Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode06
CRDBIPNode07:
# Condition: Create9Nodes
DependsOn:
- subnet2Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "6"
SubnetId: !Ref subnet2Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode07
CRDBIPNode08:
# Condition: Create9Nodes
DependsOn:
- subnet4Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 2, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "70"
SubnetId: !Ref subnet4Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode08
CRDBIPNode09:
# Condition: Create9Nodes
DependsOn:
- subnet6Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 4, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "134"
SubnetId: !Ref subnet6Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: CRDBIPNode09
HAPROXYIP:
# Condition: CreateHAProxy
# I am always going to generate the HAProxy EMI so that I can add the IP to the node certs (so that verify-full will work)
DependsOn:
- subnet2Public
- InstanceSecurityGroup01
- InstanceSecurityGroup02
Type: AWS::EC2::NetworkInterface
Properties:
PrivateIpAddress: !Join
- '.'
- - !Select [0, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [1, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- !Select [2, !Split ['.', !Select [0, !Cidr [ !Select [ 0, !Cidr [ !Ref VpcCidrParameter, 6, 5 ]], 16, 1] ] ] ]
- "7"
SubnetId: !Ref subnet2Public
GroupSet:
- !Ref InstanceSecurityGroup01
- !Ref InstanceSecurityGroup02
Tags:
- Key: Name
Value: HAProxyIP
CRDBNode01:
Condition: CreateNodes
DependsOn:
- CRDBIPNode01
- CRDBIPNode02
- CRDBIPNode03
Type: 'AWS::EC2::Instance'
Properties:
KeyName: !Ref KeyPairName
Tags:
- Key: Name
Value: !Join ['-', ['CRDB-Node-01', !Ref 'ClusterName']]
InstanceType: !Ref InstanceType
ImageId: !Ref CRDBAMIID
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: !Ref 'VolumeSize'
VolumeType: !Ref 'VolumeType'
DeleteOnTermination: 'true'
UserData:
Fn::Base64:
Fn::Sub:
- |
#!/bin/bash -xe
curl https://binaries.cockroachdb.com/cockroach-v${CockroachVersion}.linux-amd64.tgz | tar -xz && cp -i cockroach-v${CockroachVersion}.linux-amd64/cockroach /usr/local/bin/
mkdir -p /usr/local/lib/cockroach
cp -i cockroach-v${CockroachVersion}.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
cp -i cockroach-v${CockroachVersion}.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
su ec2-user -c 'mkdir /home/ec2-user/certs; mkdir /home/ec2-user/my-safe-directory'
echo '-----BEGIN RSA PRIVATE KEY-----' > /home/ec2-user/my-safe-directory/ca.key
echo 'MIIEowIBAAKCAQEAvQBvZGI4uUlVHD4REnyofo9D6JWQY13kSIkuOUur49paFkIf' >> /home/ec2-user/my-safe-directory/ca.key
echo 'mpeRSIu2u5yGf6xd7Oi3H/QnKGMlagtqt22BYqrR1IJUNMtnRSajpDBxnBlJCexy' >> /home/ec2-user/my-safe-directory/ca.key
echo 'BFVUEyLKlfcdP0HYx5jzazcL5u9obEeTn6c7dJU/Qrpou6DTa44YF4YpP3Rhrhs1' >> /home/ec2-user/my-safe-directory/ca.key
echo 'g2l6AldzJqtyfISRhL23iJz7MPScIDa4FkGcp62f1qtBt11304RNXnfrqRPEjipu' >> /home/ec2-user/my-safe-directory/ca.key
echo 'aHsuel04KMsOP70/psE5/QUtRQMH/MzBVbjRog1XFEtJpDd+ZIUpkqYb24aOgXLO' >> /home/ec2-user/my-safe-directory/ca.key
echo 'kEkbJnCQyiJBIm9jS3ilymfT0x869TXEUaPlOwIDAQABAoIBAGEttRi3TBUw+HsC' >> /home/ec2-user/my-safe-directory/ca.key
echo 'CsMnp3cTcMZJCKme4D7Pkh3Ro7sPTVy+eQOCxSe49qb2b018MfsbGPVsEyo3+EfT' >> /home/ec2-user/my-safe-directory/ca.key
echo 'QPa5blpuHF+Y93UB1MKAgIlugyvQ8HYSxfkmaolATUvYeIhK8gyGvzo0XoFKPbXX' >> /home/ec2-user/my-safe-directory/ca.key
echo 'A7eGRBLInnNP54P5yFs3/3kw+UpvSO/rWme06VO/itjXDMxw0q+H0CcbxQ/M9V9p' >> /home/ec2-user/my-safe-directory/ca.key
echo 'ptrZ4E9MzKAcCIW4vy7N7IpTGCwol6UUORJ0PeBnuj3INc1v/b015IhsTXeggb4O' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Z6oAMZsGpo4bQLGo7Ze3Og0OyCNXHPYb2dwmgfXwedBDWZoyy72eT8Abh1FM2aBE' >> /home/ec2-user/my-safe-directory/ca.key
echo 'qf9ohLkCgYEAzHPeUkZRZ6rJ0v3VAXBHYYwVJJYUfGFgpMk38Uf09ha/7CWooMHU' >> /home/ec2-user/my-safe-directory/ca.key
echo 'tOTl+V9yCot2md2SOYmBLp/1uMyPXQbWvzhjGkv1+rYbh2VYhr2AmWx7Wq4C+PPv' >> /home/ec2-user/my-safe-directory/ca.key
echo '9eUXkp3Qx7LwFl+jGsoHHcAVks07gNMUSiPW9xsfVAry84u4QrORbh8CgYEA7KdO' >> /home/ec2-user/my-safe-directory/ca.key
echo 's07YmPU3l2O5Q4mQXBHkbyCp2GwOPYyvEMxF5UV5H++TOjml3eHqT9TBYUbvueH8' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Ajk2dGsaGcxVMPxSk7AzELcfhFWH9UtSfBA/XSUPTbSp01/1PzYKlAeCH6dpf+jq' >> /home/ec2-user/my-safe-directory/ca.key
echo '/7kJNzu3lH8PvwtxNNIC/bL5KMQPyGE64KoYLWUCgYEAmyvltHQCHLgW7bgRDkJ1' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Kqfy9A2kBrKxct/1QX7ngE7L4yLB1SDHm3OOx7GVEEPBBA6SiHDARu7IxDUdKfGi' >> /home/ec2-user/my-safe-directory/ca.key
echo '0was0KyOSHYmdqCIi9sP22HmTXB8eQ5LNUlmlrSIXMiGR7TWSeLDe+Tper2hR6js' >> /home/ec2-user/my-safe-directory/ca.key
echo 'YUjKQkmngVW+BvIoKxe2bOkCgYAsucoT9VjWP7IL+Jrw+rS/0dncbs3qyzE9zLLh' >> /home/ec2-user/my-safe-directory/ca.key
echo 'd9nV5PVpZbvriy2f66x+/fS2T9PKy7z3Jpz2D6/VJFsNcQKiSvC7vgBE4G1bnKqw' >> /home/ec2-user/my-safe-directory/ca.key
echo 'K9nt3q0vwG9ANaiCE9KX+3tKRDeaJwkS34OwXqbpd8IgFyeEFhTeoc6ZN8TL2CRq' >> /home/ec2-user/my-safe-directory/ca.key
echo 'hXsgSQKBgDWNl05PYGRa9NAgzGCH0+QLgWW1AxQuD7PSgZDHLNOqvPXRbzgJIM/E' >> /home/ec2-user/my-safe-directory/ca.key
echo '3P/bKcKJAWG2muwb0m1JM8D+twaHE/QMxULkUzYtQ2nlCM6OhFYNEHkjmoB7UFA3' >> /home/ec2-user/my-safe-directory/ca.key
echo 'IaJVqjBQe91P0IKCSkZF7wFHz1YdKgjvSQOXlHD2I+MwyPF4UG6o' >> /home/ec2-user/my-safe-directory/ca.key
echo '-----END RSA PRIVATE KEY-----' >> /home/ec2-user/my-safe-directory/ca.key
echo '-----BEGIN CERTIFICATE-----' > /home/ec2-user/certs/ca.crt
echo 'MIIDJTCCAg2gAwIBAgIQDm0RAwm/Sn2RhyT5ojkTmjANBgkqhkiG9w0BAQsFADAr' >> /home/ec2-user/certs/ca.crt
echo 'MRIwEAYDVQQKEwlDb2Nrcm9hY2gxFTATBgNVBAMTDENvY2tyb2FjaCBDQTAeFw0y' >> /home/ec2-user/certs/ca.crt
echo 'MTEyMjIxNzE0MTBaFw0zMTEyMzExNzE0MTBaMCsxEjAQBgNVBAoTCUNvY2tyb2Fj' >> /home/ec2-user/certs/ca.crt
echo 'aDEVMBMGA1UEAxMMQ29ja3JvYWNoIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' >> /home/ec2-user/certs/ca.crt
echo 'MIIBCgKCAQEAvQBvZGI4uUlVHD4REnyofo9D6JWQY13kSIkuOUur49paFkIfmpeR' >> /home/ec2-user/certs/ca.crt
echo 'SIu2u5yGf6xd7Oi3H/QnKGMlagtqt22BYqrR1IJUNMtnRSajpDBxnBlJCexyBFVU' >> /home/ec2-user/certs/ca.crt
echo 'EyLKlfcdP0HYx5jzazcL5u9obEeTn6c7dJU/Qrpou6DTa44YF4YpP3Rhrhs1g2l6' >> /home/ec2-user/certs/ca.crt
echo 'AldzJqtyfISRhL23iJz7MPScIDa4FkGcp62f1qtBt11304RNXnfrqRPEjipuaHsu' >> /home/ec2-user/certs/ca.crt
echo 'el04KMsOP70/psE5/QUtRQMH/MzBVbjRog1XFEtJpDd+ZIUpkqYb24aOgXLOkEkb' >> /home/ec2-user/certs/ca.crt
echo 'JnCQyiJBIm9jS3ilymfT0x869TXEUaPlOwIDAQABo0UwQzAOBgNVHQ8BAf8EBAMC' >> /home/ec2-user/certs/ca.crt
echo 'AuQwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQUO/9ViWjopIpC8OD5tMVT' >> /home/ec2-user/certs/ca.crt
echo 'nxwRbMkwDQYJKoZIhvcNAQELBQADggEBALplxolVuvzzIHNfx4fPw2oCwcC4cBEW' >> /home/ec2-user/certs/ca.crt
echo 'x/cy4al48biFM7GnuCUJvZRcll8urCiw4J5utDuzDphWjftW2KXD8ZTctVxQ3Dli' >> /home/ec2-user/certs/ca.crt
echo 'mKBfAZPocMUKwTlBqWGNJBSuv7WDBLlIkZDHOP404vIs0Ddl+gEqarU3VS49zY7/' >> /home/ec2-user/certs/ca.crt
echo 'Ip9YN7Ch8dBGaBK1/5O2hetnsvV9ayRgQfhcvN87CRmXIqA8/SFZ8KHq7PvWVLYa' >> /home/ec2-user/certs/ca.crt
echo 'zsuodS2Txf3Z1n/s8h8GbYFdUFDcYk/n5Tb7/BfunsAWUPrH8/0uF3xZn+SlTRVF' >> /home/ec2-user/certs/ca.crt
echo 'hrg+esTLJlTzrQMAZdIE7jpN/CYyP0A/usQi03LTerr2vfv00xU+Mz8=' >> /home/ec2-user/certs/ca.crt
echo '-----END CERTIFICATE-----' >> /home/ec2-user/certs/ca.crt
chown ec2-user:ec2-user /home/ec2-user/certs/ca.crt
chown ec2-user:ec2-user /home/ec2-user/my-safe-directory/ca.key
chmod 640 /home/ec2-user/certs/ca.crt
chmod 600 /home/ec2-user/my-safe-directory/ca.key
cp /home/ec2-user/my-safe-directory/ca.key /home/ec2-user/.ssh/id_rsa
ssh-keygen -y -f /home/ec2-user/.ssh/id_rsa >> /home/ec2-user/.ssh/authorized_keys
chown ec2-user:ec2-user /home/ec2-user/.ssh/id_rsa
echo "export NODE1=${Private1}" >> /home/ec2-user/.bashrc
echo "export NODE2=${Private2}" >> /home/ec2-user/.bashrc
echo "export NODE3=${Private3}" >> /home/ec2-user/.bashrc
echo "export ip_local=\`curl http://169.254.169.254/latest/meta-data/local-ipv4\`" >> /home/ec2-user/.bashrc
echo "export ip_public=\`curl http://169.254.169.254/latest/meta-data/public-ipv4\`" >> /home/ec2-user/.bashrc
echo "export aws_region=\`curl http://169.254.169.254/latest/meta-data/placement/region\`" >> /home/ec2-user/.bashrc
echo "export aws_az=\`curl http://169.254.169.254/latest/meta-data/placement/availability-zone\`" >> /home/ec2-user/.bashrc
echo "export cockroach_data_dir=/home/ec2-user/cockroach-data" >> /home/ec2-user/.bashrc
echo "if [ '${ExistingJoinString}' = 'NONE' ]; then" >> /home/ec2-user/.bashrc
echo " export JOIN_STR=${CRDBIPNode01.PrimaryPrivateIpAddress},${CRDBIPNode02.PrimaryPrivateIpAddress},${CRDBIPNode03.PrimaryPrivateIpAddress}" >> /home/ec2-user/.bashrc
echo "else" >> /home/ec2-user/.bashrc
echo " export JOIN_STR=${ExistingJoinString}" >> /home/ec2-user/.bashrc
echo "fi" >> /home/ec2-user/.bashrc
echo "export COCKROACH_CERTS_DIR=/home/ec2-user/certs" >> /home/ec2-user/.bashrc
echo "export CRDBNODE=1" >> /home/ec2-user/.bashrc
export CRDBNODE=1
echo "STARTCRDB() {" >> /home/ec2-user/.bashrc
echo " cockroach start \\" >> /home/ec2-user/.bashrc
echo ' --locality=region="$aws_region",zone="$aws_az" \' >> /home/ec2-user/.bashrc
echo " --certs-dir=certs \\" >> /home/ec2-user/.bashrc
echo ' --advertise-addr=$ip_local \' >> /home/ec2-user/.bashrc
echo ' --join=$JOIN_STR \' >> /home/ec2-user/.bashrc
echo ' --max-offset=250ms \' >> /home/ec2-user/.bashrc
echo " --background " >> /home/ec2-user/.bashrc
echo " }" >> /home/ec2-user/.bashrc
echo "CREATENODECERT() {" >> /home/ec2-user/.bashrc
echo " cockroach cert create-node \\" >> /home/ec2-user/.bashrc
echo ' $ip_local \' >> /home/ec2-user/.bashrc
echo ' $ip_public \' >> /home/ec2-user/.bashrc
echo " localhost \\" >> /home/ec2-user/.bashrc
echo " 127.0.0.1 \\" >> /home/ec2-user/.bashrc
echo " ${Private0} \\" >> /home/ec2-user/.bashrc
echo " --certs-dir=certs \\" >> /home/ec2-user/.bashrc
echo " --ca-key=my-safe-directory/ca.key" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "CREATEROOTCERT() {" >> /home/ec2-user/.bashrc
echo " cockroach cert create-client \\" >> /home/ec2-user/.bashrc
echo ' root \' >> /home/ec2-user/.bashrc
echo " --certs-dir=certs \\" >> /home/ec2-user/.bashrc
echo " --ca-key=my-safe-directory/ca.key" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "REFRESHCRDB() {" >> /home/ec2-user/.bashrc
echo " ps -ef | grep "cockroach" | grep -v grep | awk '{print \$2}' | xargs kill -9" >> /home/ec2-user/.bashrc
echo " rm -rf \$cockroach_data_dir" >> /home/ec2-user/.bashrc
echo " mkdir -p \$cockroach_data_dir" >> /home/ec2-user/.bashrc
echo " chmod 750 \$cockroach_data_dir" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 1 ]]; then echo "Sleeping for 30 seconds. Refresh other nodes in the cluster before the 30 second timer expires."; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" != 3 ]]; then sleep 30; fi" >> /home/ec2-user/.bashrc
echo " STARTCRDB" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then echo "Sleeping while other cluster nodes start" && sleep 30 && echo "Initializing Cockroach Database" && cockroach init; fi" >> /home/ec2-user/.bashrc
echo " if [[ "$CRDBNODE" = 3 ]]; then sleep 15; cockroach node status; fi" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS() {" >> /home/ec2-user/.bashrc
echo " cockroach node status | awk -F ':' 'FNR > 1 { print \$1 }' | awk '{ print \$1, \$2 }' | while read line; do" >> /home/ec2-user/.bashrc
echo " node_number=\`echo \$line | awk '{ print \$1 }'\`" >> /home/ec2-user/.bashrc
echo " variable_name=CRDBNODE\$node_number" >> /home/ec2-user/.bashrc
echo " ip=\`echo \$line | awk '{ print \$2 }'\`" >> /home/ec2-user/.bashrc
echo " echo export \$variable_name=\$ip >> crdb_node_list" >> /home/ec2-user/.bashrc
echo " done" >> /home/ec2-user/.bashrc
echo " source ./crdb_node_list" >> /home/ec2-user/.bashrc
echo "}" >> /home/ec2-user/.bashrc
echo "SETCRDBVARS" >> /home/ec2-user/.bashrc
sleep 20; su ec2-user -lc 'CREATENODECERT; CREATEROOTCERT; STARTCRDB'
if [[ '${RunInit}' = 'YES' && "$CRDBNODE" = 3 ]]; then echo "Initializing Cockroach Database" && su ec2-user -lc 'cockroach init'; fi
if [[ '${Installpsql}' = 'YES' ]]; then echo "Installing postgresql13"; amazon-linux-extras install postgresql13; fi
- Private1: !GetAtt CRDBIPNode01.PrimaryPrivateIpAddress
Private2: !GetAtt CRDBIPNode02.PrimaryPrivateIpAddress
Private3: !GetAtt CRDBIPNode03.PrimaryPrivateIpAddress
Private0: !GetAtt HAPROXYIP.PrimaryPrivateIpAddress
NetworkInterfaces:
- DeviceIndex: '0'
NetworkInterfaceId: !Ref CRDBIPNode01
CRDBNode02:
Condition: CreateNodes
DependsOn:
- CRDBIPNode01
- CRDBIPNode02
- CRDBIPNode03
Type: 'AWS::EC2::Instance'
Properties:
KeyName: !Ref KeyPairName
Tags:
- Key: Name
Value: !Join ['-', ['CRDB-Node-02', !Ref 'ClusterName']]
InstanceType: !Ref InstanceType
ImageId: !Ref CRDBAMIID
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: !Ref 'VolumeSize'
VolumeType: !Ref 'VolumeType'
DeleteOnTermination: 'true'
UserData:
Fn::Base64:
Fn::Sub:
- |
#!/bin/bash -xe
curl https://binaries.cockroachdb.com/cockroach-v${CockroachVersion}.linux-amd64.tgz | tar -xz && cp -i cockroach-v${CockroachVersion}.linux-amd64/cockroach /usr/local/bin/
mkdir -p /usr/local/lib/cockroach
cp -i cockroach-v${CockroachVersion}.linux-amd64/lib/libgeos.so /usr/local/lib/cockroach/
cp -i cockroach-v${CockroachVersion}.linux-amd64/lib/libgeos_c.so /usr/local/lib/cockroach/
su ec2-user -c 'mkdir /home/ec2-user/certs; mkdir /home/ec2-user/my-safe-directory'
echo '-----BEGIN RSA PRIVATE KEY-----' > /home/ec2-user/my-safe-directory/ca.key
echo 'MIIEowIBAAKCAQEAvQBvZGI4uUlVHD4REnyofo9D6JWQY13kSIkuOUur49paFkIf' >> /home/ec2-user/my-safe-directory/ca.key
echo 'mpeRSIu2u5yGf6xd7Oi3H/QnKGMlagtqt22BYqrR1IJUNMtnRSajpDBxnBlJCexy' >> /home/ec2-user/my-safe-directory/ca.key
echo 'BFVUEyLKlfcdP0HYx5jzazcL5u9obEeTn6c7dJU/Qrpou6DTa44YF4YpP3Rhrhs1' >> /home/ec2-user/my-safe-directory/ca.key
echo 'g2l6AldzJqtyfISRhL23iJz7MPScIDa4FkGcp62f1qtBt11304RNXnfrqRPEjipu' >> /home/ec2-user/my-safe-directory/ca.key
echo 'aHsuel04KMsOP70/psE5/QUtRQMH/MzBVbjRog1XFEtJpDd+ZIUpkqYb24aOgXLO' >> /home/ec2-user/my-safe-directory/ca.key
echo 'kEkbJnCQyiJBIm9jS3ilymfT0x869TXEUaPlOwIDAQABAoIBAGEttRi3TBUw+HsC' >> /home/ec2-user/my-safe-directory/ca.key
echo 'CsMnp3cTcMZJCKme4D7Pkh3Ro7sPTVy+eQOCxSe49qb2b018MfsbGPVsEyo3+EfT' >> /home/ec2-user/my-safe-directory/ca.key
echo 'QPa5blpuHF+Y93UB1MKAgIlugyvQ8HYSxfkmaolATUvYeIhK8gyGvzo0XoFKPbXX' >> /home/ec2-user/my-safe-directory/ca.key
echo 'A7eGRBLInnNP54P5yFs3/3kw+UpvSO/rWme06VO/itjXDMxw0q+H0CcbxQ/M9V9p' >> /home/ec2-user/my-safe-directory/ca.key
echo 'ptrZ4E9MzKAcCIW4vy7N7IpTGCwol6UUORJ0PeBnuj3INc1v/b015IhsTXeggb4O' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Z6oAMZsGpo4bQLGo7Ze3Og0OyCNXHPYb2dwmgfXwedBDWZoyy72eT8Abh1FM2aBE' >> /home/ec2-user/my-safe-directory/ca.key
echo 'qf9ohLkCgYEAzHPeUkZRZ6rJ0v3VAXBHYYwVJJYUfGFgpMk38Uf09ha/7CWooMHU' >> /home/ec2-user/my-safe-directory/ca.key
echo 'tOTl+V9yCot2md2SOYmBLp/1uMyPXQbWvzhjGkv1+rYbh2VYhr2AmWx7Wq4C+PPv' >> /home/ec2-user/my-safe-directory/ca.key
echo '9eUXkp3Qx7LwFl+jGsoHHcAVks07gNMUSiPW9xsfVAry84u4QrORbh8CgYEA7KdO' >> /home/ec2-user/my-safe-directory/ca.key
echo 's07YmPU3l2O5Q4mQXBHkbyCp2GwOPYyvEMxF5UV5H++TOjml3eHqT9TBYUbvueH8' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Ajk2dGsaGcxVMPxSk7AzELcfhFWH9UtSfBA/XSUPTbSp01/1PzYKlAeCH6dpf+jq' >> /home/ec2-user/my-safe-directory/ca.key
echo '/7kJNzu3lH8PvwtxNNIC/bL5KMQPyGE64KoYLWUCgYEAmyvltHQCHLgW7bgRDkJ1' >> /home/ec2-user/my-safe-directory/ca.key
echo 'Kqfy9A2kBrKxct/1QX7ngE7L4yLB1SDHm3OOx7GVEEPBBA6SiHDARu7IxDUdKfGi' >> /home/ec2-user/my-safe-directory/ca.key
echo '0was0KyOSHYmdqCIi9sP22HmTXB8eQ5LNUlmlrSIXMiGR7TWSeLDe+Tper2hR6js' >> /home/ec2-user/my-safe-directory/ca.key
echo 'YUjKQkmngVW+BvIoKxe2bOkCgYAsucoT9VjWP7IL+Jrw+rS/0dncbs3qyzE9zLLh' >> /home/ec2-user/my-safe-directory/ca.key
echo 'd9nV5PVpZbvriy2f66x+/fS2T9PKy7z3Jpz2D6/VJFsNcQKiSvC7vgBE4G1bnKqw' >> /home/ec2-user/my-safe-directory/ca.key
echo 'K9nt3q0vwG9ANaiCE9KX+3tKRDeaJwkS34OwXqbpd8IgFyeEFhTeoc6ZN8TL2CRq' >> /home/ec2-user/my-safe-directory/ca.key
echo 'hXsgSQKBgDWNl05PYGRa9NAgzGCH0+QLgWW1AxQuD7PSgZDHLNOqvPXRbzgJIM/E' >> /home/ec2-user/my-safe-directory/ca.key