-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresearchnode.yaml
More file actions
241 lines (239 loc) · 6.69 KB
/
Copy pathresearchnode.yaml
File metadata and controls
241 lines (239 loc) · 6.69 KB
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
Description: Template to spin up research node for node research group
Parameters:
EnvironmentName:
Description: An environment name that will be prefixed to resource name
Type: String
ProjectName:
Description: Name of the project, that will be used as a tag for sorting costs and usage
Type: String
KeyName:
Description: The EC2 Key Pair to allow SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
Default: keyname
VPC:
Description: VPC for security groups to be created into
Type: AWS::EC2::VPC::Id
Subnet:
Description: Subnet to deploy server in
Type: AWS::EC2::Subnet::Id
InstanceType:
Description: EC2 instance type for the node instances
Type: String
Default: c5.2xlarge
AllowedValues:
- t2.small
- t2.medium
- t2.large
- t2.xlarge
- t2.2xlarge
- t3.nano
- t3.micro
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3.2xlarge
- m3.medium
- m3.large
- m3.xlarge
- m3.2xlarge
- m4.large
- m4.xlarge
- m4.2xlarge
- m4.4xlarge
- m4.10xlarge
- m5.large
- m5.xlarge
- m5.2xlarge
- m5.4xlarge
- m5.12xlarge
- m5.24xlarge
- c4.large
- c4.xlarge
- c4.2xlarge
- c4.4xlarge
- c4.8xlarge
- c5.large
- c5.xlarge
- c5.2xlarge
- c5.4xlarge
- c5.9xlarge
- c5.18xlarge
- i3.large
- i3.xlarge
- i3.2xlarge
- i3.4xlarge
- i3.8xlarge
- i3.16xlarge
- r3.xlarge
- r3.2xlarge
- r3.4xlarge
- r3.8xlarge
- r4.large
- r4.xlarge
- r4.2xlarge
- r4.4xlarge
- r4.8xlarge
- r4.16xlarge
- x1.16xlarge
- x1.32xlarge
- p2.xlarge
- p2.8xlarge
- p2.16xlarge
- p3.2xlarge
- p3.8xlarge
- p3.16xlarge
- r5.large
- r5.xlarge
- r5.2xlarge
- r5.4xlarge
- r5.12xlarge
- r5.24xlarge
- r5d.large
- r5d.xlarge
- r5d.2xlarge
- r5d.4xlarge
- r5d.12xlarge
- r5d.24xlarge
- z1d.large
- z1d.xlarge
- z1d.2xlarge
- z1d.3xlarge
- z1d.6xlarge
- z1d.12xlarge
ConstraintDescription: Must be a valid EC2 instance type
Hostname:
Description: Hostname for the system server (FQDN)
Type: String
Default: ubuntu.my.domain
VolumeSize:
Type: Number
Description: Server volume size
Default: 25
RemoteSSHSource:
Description: Sources for SSH access
Type: String
Resources:
node:
Type: AWS::EC2::Instance
Properties:
SecurityGroupIds:
- !Ref nodeICMPSecurityGroup
- !Ref nodeSSHSecurityGroup
KeyName: !Ref KeyName
InstanceType: !Ref InstanceType
ImageId: ami-07b4f3c02c7f83d59 #using Ubuntu 18.04 Bionic Beaver LTS
#SubnetId: !Sub ${Subnet} # ommiting since security groups are getting created in same template
Tags:
- Key: Deployment
Value: !Ref 'EnvironmentName'
- Key: Name
Value: !Ref $Hostname
- Key: Project
Value: !Ref ProjectName
BlockDeviceMappings:
- DeviceName: /dev/sda1 # Yes this is right, even though it should be mapping to /dev/xvda
Ebs:
VolumeSize: !Ref VolumeSize
VolumeType: gp2
DeleteOnTermination: false
UserData:
Fn::Base64: !Sub |
#!/bin/bash
apt-get update -y
apt-get install -y python-pip
apt-get install -y python-setuptools
mkdir -p /opt/aws/bin
python /usr/lib/python2.7/dist-packages/easy_install.py --script-dir /opt/aws/bin https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource node --configsets setup,general --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e --stack ${AWS::StackName} --resource node --configsets setup,general --region ${AWS::Region}
Metadata:
AWS::CloudFormation::Init:
configSets:
setup:
- "configure_cfn"
general:
- "hostname"
- "hosts"
- "apt_get_upgrade"
configure_cfn:
files:
/etc/cfn/cfn-hup.conf:
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
verbose=true
interval=5
mode: "000400"
owner: root
group: root
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.EC2.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2 --configsets setup --region ${AWS::Region}
mode: "000400"
owner: root
group: root
/lib/systemd/system/cfn-hup.service:
content: !Sub |
[Unit]
Description=cfn-hup daemon
[Service]
Type=simple
ExecStart=/opt/aws/bin/cfn-hup
Restart=always
[Install]
WantedBy=multi-user.target
mode: "000400"
owner: root
group: root
commands:
01_enable_cfn-hup:
command: "systemctl enable cfn-hup.service"
02_start_cfn-hup:
command: "systemctl start cfn-hup.service"
hostname:
commands:
hostname:
command: !Ref "sudo hostnamectl set-hostname $Hostname"
ignoreErrors: true
hosts:
commands:
hosts:
command: !Ref "sudo echo $Hostname"
apt_get_upgrade:
commands:
apt_get_upgrade:
command: "sudo apt-get update && sudo apt-get upgrade -y"
nodeICMPSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
DependsOn: nodeHTTPSSecurityGroup
Properties:
GroupDescription: Enable ICMP access to server
SecurityGroupIngress:
- IpProtocol: icmp
FromPort: '8'
ToPort: '-1'
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub ${EnvironmentName}-ICMP
- Key: Project
Value: !Ref ProjectName
nodeSSHSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access to the servers
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref RemoteSSHSource
Tags:
- Key: Name
Value: !Sub ${EnvironmentName}-SSH
- Key: Project
Value: !Ref ProjectName