-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-windows-bastion.yaml
159 lines (141 loc) · 4.41 KB
/
ec2-windows-bastion.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
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
# aws cloudformation create-stack --capabilities CAPABILITY_NAMED_IAM --stack-name windows-bastion-us-east-1-demo --template-body file://ec2-windows-bastion.yaml --parameters file://params/windows-bastion-params-us-east-1-demo.json
AWSTemplateFormatVersion: '2010-09-09'
Description: >
This template creates a Windows Bastion EC2 instance.
Parameters:
DeploymentId:
Type: String
Description: A unique deployment identifier.
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Description: EC2 KeyPair to enable SSH access to the ECS instances.
InstanceType:
Description: EC2 instance type
Type: String
Default: t2.micro
AllowedValues: [t2.micro, t2.small, t2.medium, t2.large]
ConstraintDescription: Please choose a valid instance type.
Service:
Type: String
Description: Name of the service or product that is associated with this stack.
Owner:
Type: String
Description: Email address of the person that created the stack.
AmiId:
Type: String
Description: Amazon Machine Image ID
Resources:
### EC2 ###
WindowsBastionEc2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref 'AmiId'
InstanceType: !Ref 'InstanceType'
SubnetId: !ImportValue 'PublicSubnetAz1'
KeyName: !Ref 'KeyName'
SecurityGroupIds: [!Ref 'WindowsBastionEc2SecurityGroup']
IamInstanceProfile: !Ref 'WindowsBastionInstanceProfile'
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: '50'
VolumeType: 'gp2'
Tags:
- Key: Name
Value: !Sub ${Service}-${DeploymentId}
- Key: Service
Value: !Ref 'Service'
- Key: Owner
Value: !Ref 'Owner'
### EC2 EIP ###
WindowsBastionEc2Eip:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
InstanceId: !Ref 'WindowsBastionEc2Instance'
### Route 53 ###
WindowsBastionDnsRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneName: !Ref 'HostedZoneName'
Comment: DNS name for Windows Bastion instance.
Name: !Join ['', [!Ref 'Service', ., !Ref 'HostedZoneName']]
Type: A
TTL: '300'
ResourceRecords:
- !Ref 'WindowsBastionEc2Eip'
### Security Groups ###
WindowsBastionEc2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: WindowsBastion Security Group
VpcId: !ImportValue 'VpcId'
Tags:
- Key: Service
Value: windows-bastion
- Key: Name
Value: windows-bastion-ec2-sg
# Allow RDP port 3389 access to Windows Bastion EC2 instance from specific addresses
WindowsBastionEc2SecurityGroupSshInbound:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref 'WindowsBastionEc2SecurityGroup'
IpProtocol: tcp
FromPort: '3389'
ToPort: '3389'
CidrIp: 5.5.5.5/32
### IAM Role & Policies ###
WindowsBastionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Path: /
# Allow Windows Bastion service access to Assume IAM roles
WindowsBastionAssumeRolePolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: WindowsBastionAssumeRolePolicy
Roles:
- !Ref 'WindowsBastionRole'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- sts:AssumeRole
Resource:
- '*'
# Allow Windows Bastion service access to CloudWatch
WindowsBastionCloudWatchPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: WindowsBastionCloudWatchPolicy
Roles:
- !Ref 'WindowsBastionRole'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- cloudwatch:List*
- cloudwatch:Get*
- cloudwatch:PutMetricData
Resource: '*'
# Windows Bastion EC2 Instance profile for which the Windows Bastion IAM role is associated
WindowsBastionInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: /
Roles:
- !Ref 'WindowsBastionRole'
### Outputs:
# WindowsBastionEc2InstancePrivateDnsName:
# Value: !GetAtt WindowsBastionEc2Instance.PrivateDnsName