main.yml 4.3 KB

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