-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjumpbox.yml
185 lines (169 loc) · 4.55 KB
/
jumpbox.yml
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
Description: >
Luis Fernandez / UdacityProjectLuis
This template deploys a Jumpbox/Bastion Server
Parameters:
EnvironmentName:
Description: An Environment name that will be prefixed to resources
Type: String
NetworkAccessIP:
Description: Source that has SSH access to the jump box host
Type: String
JumpBoxSSHS3Bucket:
Description: Bucket name for Application
Type: String
JumpBoxSSHKeyName:
Description: JumpBox Host SSH Key Name
Type: 'AWS::EC2::KeyPair::KeyName'
Resources:
IamRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
IamPolicies:
Type: AWS::IAM::Policy
Properties:
PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: "s3:*"
Resource: "*"
Roles:
- !Ref IamRole
IamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- !Ref IamRole
JumpBoxSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SSH Access to JumpBox Instance
VpcId:
Fn::ImportValue:
!Sub "${EnvironmentName}-VPC-ID"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Sub ${NetworkAccessIP}
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
JumpBoxEC2InstanceOne:
Type: AWS::EC2::Instance
DependsOn:
- JumpBoxSecurityGroup
- IamInstanceProfile
Properties:
IamInstanceProfile: !Ref IamInstanceProfile
ImageId: ami-07b4f3c02c7f83d59
InstanceType: t3.small
KeyName: !Sub ${JumpBoxSSHKeyName}
SecurityGroupIds:
- Ref: JumpBoxSecurityGroup
SubnetId:
Fn::ImportValue:
!Sub "${EnvironmentName}-PUBLIC-ONE-SUBNET"
UserData:
Fn::Base64: !Sub |
#!/bin/bash
apt-get update -y
apt-get install unzip awscli -y
cd /home/ubuntu
aws s3 cp s3://${JumpBoxSSHS3Bucket}/${JumpBoxSSHKeyName}.pem /home/ubuntu
chmod 400 ${JumpBoxSSHKeyName}.pem
EIPOne:
Type: AWS::EC2::EIP
Properties:
Domain:
Fn::ImportValue:
!Sub "${EnvironmentName}-VPC-ID"
EIPAssociationOne:
Type: AWS::EC2::EIPAssociation
DependsOn:
- JumpBoxEC2InstanceOne
- EIPOne
Properties:
InstanceId:
Ref: JumpBoxEC2InstanceOne
AllocationId:
Fn::GetAtt:
- EIPOne
- AllocationId
JumpBoxEC2InstanceTwo:
Type: AWS::EC2::Instance
DependsOn:
- JumpBoxSecurityGroup
- IamInstanceProfile
Properties:
IamInstanceProfile: !Ref IamInstanceProfile
ImageId: ami-07b4f3c02c7f83d59
InstanceType: t3.small
KeyName: !Sub ${JumpBoxSSHKeyName}
SecurityGroupIds:
- Ref: JumpBoxSecurityGroup
SubnetId:
Fn::ImportValue:
!Sub "${EnvironmentName}-PUBLIC-TWO-SUBNET"
UserData:
Fn::Base64: !Sub |
#!/bin/bash
apt-get update -y
apt-get install unzip awscli -y
cd /home/ubuntu
aws s3 cp s3://${JumpBoxSSHS3Bucket}/${JumpBoxSSHKeyName}.pem /home/ubuntu
chmod 400 ${JumpBoxSSHKeyName}.pem
EIPTwo:
Type: AWS::EC2::EIP
Properties:
Domain:
Fn::ImportValue:
!Sub "${EnvironmentName}-VPC-ID"
EIPAssociationTwo:
Type: AWS::EC2::EIPAssociation
DependsOn:
- JumpBoxEC2InstanceTwo
- EIPTwo
Properties:
InstanceId:
Ref: JumpBoxEC2InstanceTwo
AllocationId:
Fn::GetAtt:
- EIPTwo
- AllocationId
Outputs:
JumpBoxHostOneCIDR:
Description: A reference to the JumpBox Host CIDR
Value:
!Join
- ''
- - !GetAtt JumpBoxEC2InstanceOne.PrivateIp
- !Sub '/32'
Export:
Name: !Sub ${EnvironmentName}-BASTION-ONE-HOST-CIDR
JumpBoxHost2CIDR:
Description: A reference to the JumpBox Host CIDR
Value:
!Join
- ''
- - !GetAtt JumpBoxEC2InstanceTwo.PrivateIp
- !Sub '/32'
Export:
Name: !Sub ${EnvironmentName}-BASTION-TWO-HOST-CIDR
JumpBoxHostSSHKeyName:
Description: A reference to the JumpBox Host SSH Key Name
Value: !Sub ${JumpBoxSSHKeyName}
Export:
Name: !Sub ${EnvironmentName}-BASTION-SSH-KEY-NAME