main.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Parameters:
  3. EC2InstanceType:
  4. Type: String
  5. EC2AMI:
  6. Type: String
  7. Default: 'ami-09e67e426f25ce0d7'
  8. DefaultAMI:
  9. Type: String
  10. Default: 'ami-09e67e426f25ce0d7'
  11. KeyName:
  12. Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
  13. Type: 'AWS::EC2::KeyPair::KeyName'
  14. Default: 'joystream-key'
  15. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  16. Conditions:
  17. HasAMIId: !Not [!Equals [!Ref EC2AMI, ""]]
  18. Resources:
  19. SecurityGroup:
  20. Type: AWS::EC2::SecurityGroup
  21. Properties:
  22. GroupDescription:
  23. !Sub 'Internal Security group for validator nodes ${AWS::StackName}'
  24. SecurityGroupIngress:
  25. - IpProtocol: tcp
  26. FromPort: 30333
  27. ToPort: 30333
  28. CidrIp: 0.0.0.0/0
  29. - IpProtocol: tcp
  30. FromPort: 22
  31. ToPort: 22
  32. CidrIp: 0.0.0.0/0
  33. Tags:
  34. - Key: Name
  35. Value: !Sub '${AWS::StackName}_validator'
  36. RPCSecurityGroup:
  37. Type: AWS::EC2::SecurityGroup
  38. Properties:
  39. GroupDescription:
  40. !Sub 'Internal Security group for RPC nodes ${AWS::StackName}'
  41. SecurityGroupIngress:
  42. - IpProtocol: tcp
  43. FromPort: 9933
  44. ToPort: 9933
  45. CidrIp: 0.0.0.0/0
  46. - IpProtocol: tcp
  47. FromPort: 9944
  48. ToPort: 9944
  49. CidrIp: 0.0.0.0/0
  50. - IpProtocol: tcp
  51. FromPort: 22
  52. ToPort: 22
  53. CidrIp: 0.0.0.0/0
  54. Tags:
  55. - Key: Name
  56. Value: !Sub '${AWS::StackName}_rpc'
  57. InstanceLaunchTemplate:
  58. Type: AWS::EC2::LaunchTemplate
  59. Metadata:
  60. AWS::CloudFormation::Init:
  61. config:
  62. packages:
  63. apt:
  64. wget: []
  65. unzip: []
  66. Properties:
  67. LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
  68. LaunchTemplateData:
  69. ImageId: !If [HasAMIId, !Ref EC2AMI, !Ref DefaultAMI]
  70. InstanceType: !Ref EC2InstanceType
  71. KeyName: !Ref KeyName
  72. SecurityGroupIds:
  73. - !GetAtt SecurityGroup.GroupId
  74. BlockDeviceMappings:
  75. - DeviceName: /dev/sda1
  76. Ebs:
  77. VolumeSize: '40'
  78. UserData:
  79. Fn::Base64: !Sub |
  80. #!/bin/bash -xe
  81. # send script output to /tmp so we can debug boot failures
  82. exec > /tmp/userdata.log 2>&1
  83. # Update all packages
  84. apt-get update -y
  85. # Install the updates
  86. apt-get upgrade -y
  87. # Get latest cfn scripts and install them;
  88. apt-get install -y python3-setuptools
  89. mkdir -p /opt/aws/bin
  90. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  91. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  92. /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
  93. Instance:
  94. Type: AWS::EC2::Instance
  95. Properties:
  96. LaunchTemplate:
  97. LaunchTemplateId: !Ref InstanceLaunchTemplate
  98. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  99. Tags:
  100. - Key: Name
  101. Value: !Sub '${AWS::StackName}_1'
  102. Instance2:
  103. Type: AWS::EC2::Instance
  104. Properties:
  105. LaunchTemplate:
  106. LaunchTemplateId: !Ref InstanceLaunchTemplate
  107. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  108. Tags:
  109. - Key: Name
  110. Value: !Sub '${AWS::StackName}_2'
  111. RPCInstance:
  112. Type: AWS::EC2::Instance
  113. Properties:
  114. SecurityGroupIds:
  115. - !GetAtt RPCSecurityGroup.GroupId
  116. LaunchTemplate:
  117. LaunchTemplateId: !Ref InstanceLaunchTemplate
  118. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  119. Tags:
  120. - Key: Name
  121. Value: !Sub '${AWS::StackName}_rpc'
  122. BuildInstance:
  123. Type: AWS::EC2::Instance
  124. Properties:
  125. LaunchTemplate:
  126. LaunchTemplateId: !Ref InstanceLaunchTemplate
  127. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  128. Tags:
  129. - Key: Name
  130. Value: !Sub '${AWS::StackName}_build'
  131. WaitHandle:
  132. Type: AWS::CloudFormation::WaitConditionHandle
  133. WaitCondition:
  134. Type: AWS::CloudFormation::WaitCondition
  135. Properties:
  136. Handle: !Ref 'WaitHandle'
  137. Timeout: '600'
  138. Count: 4
  139. Outputs:
  140. PublicIp:
  141. Description: The DNS name for the created instance
  142. Value: !Sub "${Instance.PublicIp}"
  143. Export:
  144. Name: !Sub "${AWS::StackName}PublicIp"
  145. PublicIp2:
  146. Description: The DNS name for the created instance
  147. Value: !Sub "${Instance2.PublicIp}"
  148. Export:
  149. Name: !Sub "${AWS::StackName}PublicIp2"
  150. RPCPublicIp:
  151. Description: The DNS name for the created instance
  152. Value: !Sub "${RPCInstance.PublicIp}"
  153. Export:
  154. Name: !Sub "${AWS::StackName}RPCPublicIp"
  155. BuildPublicIp:
  156. Description: The DNS name for the created instance
  157. Value: !Sub "${BuildInstance.PublicIp}"
  158. Export:
  159. Name: !Sub "${AWS::StackName}BuildPublicIp"