-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfn.yaml
More file actions
65 lines (54 loc) · 1.82 KB
/
cfn.yaml
File metadata and controls
65 lines (54 loc) · 1.82 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
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Protohackers challenge - t2.micro (Ubuntu 22.04)"
Parameters:
KeyName:
Description: The EC2 Key Pair to allow SSH access to the instance
Type: "AWS::EC2::KeyPair::KeyName"
ConstraintDescription: "Must be the name of an existing EC2 key pair"
CheckerAddr:
Description: The Protohackers checker IP address
Type: "String"
MinLength: 9
MaxLength: 18
AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
ConstraintDescription: "Must be a valid IP CIDR range of the form x.x.x.x/x"
Resources:
EC2Instance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: "t2.micro"
SecurityGroups: [!Ref InstanceSecurityGroup]
KeyName: !Ref KeyName
ImageId: ami-051f7c00cb18501ee # eu-west-1, Ubuntu 22.04 (20220901 release)
Tags:
- {"Key": "Name", "Value": "protohackers-box"}
UserData:
Fn::Base64: |
#cloud-config
package_update: true
package_upgrade: true
packages: [golang]
runcmd:
- [runuser, -c, 'git clone https://github.com/tlgs/protohackers $HOME/protohackers', ubuntu]
InstanceSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Enable SSH (22), and application ports (1000x) to the Protohackers checker"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 10000
ToPort: 10005
CidrIp: !Ref CheckerAddr
- IpProtocol: udp
FromPort: 10000
ToPort: 10005
CidrIp: !Ref CheckerAddr
Outputs:
InstanceId:
Description: "InstanceId of the newly created EC2 instance"
Value: !Ref EC2Instance