-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
87 lines (83 loc) · 2.39 KB
/
template.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
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS K3D
Parameters:
InstanceType:
Description: EC2 instance type on which K3D runs
Type: String
Default: t2.micro
KeyPairName:
Type: String
AmiId:
Type: String
PemKeyFileUrl:
Type: String
UserData:
Type: String
Default: ""
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
SecurityGroups: [!Ref InstanceSecurityGroup]
KeyName: !Ref KeyPairName
ImageId: !Ref AmiId
UserData:
Fn::Base64:
!Sub
- |
#!/bin/bash -x
${UserData}
/opt/aws/bin/cfn-signal -e 0 --stack ${StackName} -r "EC2Instance" --region ${Region} ${WaitHandleHash}
-
WaitHandleHash:
Fn::Base64: !Ref WaitHandle
StackName: !Ref AWS::StackName
Region: !Ref AWS::Region
UserData: !Ref UserData
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22 and TCP access via ports 80, 8000, 8080
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: 8000
ToPort: 8000
CidrIp: "0.0.0.0/0"
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
CidrIp: "0.0.0.0/0"
WaitHandle:
Type: AWS::CloudFormation::WaitConditionHandle
WaitCondition:
Type: AWS::CloudFormation::WaitCondition
DependsOn: "EC2Instance"
Properties:
Handle:
Ref: "WaitHandle"
Timeout: "300"
Count: 1
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref EC2Instance
AZ:
Description: Availability Zone of the newly created EC2 instance
Value: !GetAtt [EC2Instance, AvailabilityZone]
PublicDNS:
Description: Public DNSName of the newly created EC2 instance
Value: !GetAtt [EC2Instance, PublicDnsName]
PublicIP:
Description: Public IP address of the newly created EC2 instance
Value: !GetAtt [EC2Instance, PublicIp]
PemKeyFileUrl:
Value: !Sub '${PemKeyFileUrl}'