-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtpl-basic.yaml
118 lines (108 loc) · 2.98 KB
/
tpl-basic.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
AWSTemplateFormatVersion: "2010-09-09"
Description: Sandbox server template (basic)
Parameters:
InstanceType:
Description: "EC2 instance type (default: t3.small = 2 vCPU, 2GB RAM)"
Type: String
Default: t3.small
AllowedValues:
- t3.small
- t3.medium
- t3.large
- t3.xlarge
- t3.2xlarge
KeyName:
Description: "Name of an existing EC2 KeyPair to enable SSH access to the instance"
Type: "AWS::EC2::KeyPair::KeyName"
ConstraintDescription: "Must be the name of an existing EC2 KeyPair"
DataDiskSize:
Description: "Persistent volume size (GiB). Valid range: 20-1024"
Type: Number
MinValue: 20
MaxValue: 1024
Default: 100
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Basic: Required"
Parameters:
- InstanceType
- KeyName
- Label:
default: "Advanced: Optional"
Parameters:
- DataDiskSize
ParameterLabels:
InstanceType:
default: "Instance type"
KeyName:
default: "SSH key"
DataDiskSize:
default: "Data disk size"
Mappings:
Variables:
LatestAmiId:
# Get the latest AMI ID from Canonical's public Systems Manager Parameter
amd64: "{{resolve:ssm:/aws/service/canonical/ubuntu/server/22.04/stable/current/amd64/hvm/ebs-gp2/ami-id}}"
Resources:
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'Enable SSH, HTTP, HTTPS'
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
IPAddress:
Type: 'AWS::EC2::EIP'
IPAssoc:
Type: 'AWS::EC2::EIPAssociation'
Properties:
InstanceId: !Ref ec2Instance
EIP: !Ref IPAddress
PersistentVolume:
Type: "AWS::EC2::Volume"
Properties:
Size: !Ref DataDiskSize
AvailabilityZone: !GetAtt ec2Instance.AvailabilityZone
PersistentVolumeMount:
Type: "AWS::EC2::VolumeAttachment"
Properties:
InstanceId: !Ref ec2Instance
VolumeId: !Ref PersistentVolume
Device: /dev/sdp
ec2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: !Ref InstanceType
AvailabilityZone: !Ref "AWS::NoValue"
ImageId: !FindInMap [Variables, LatestAmiId, amd64]
KeyName: !Ref KeyName
SecurityGroups:
- !Ref InstanceSecurityGroup
BlockDeviceMappings:
# Root volume
- DeviceName: /dev/sda1
Ebs:
VolumeSize: '8'
UserData: !Base64
'Fn::Join':
- ''
- - |
Outputs:
InstanceID:
Value: !Ref ec2Instance
IPAddress:
Value: !GetAtt ec2Instance.PublicIp
InstanceURL:
Value: !Join [ '', [ 'https://', !GetAtt ec2Instance.PublicIp, '.nip.io' ] ]