-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2.DOCTANK_CGW.yml
222 lines (196 loc) · 5.1 KB
/
2.DOCTANK_CGW.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
AWSTemplateFormatVersion: "2010-09-09"
Description: "CGW Config for Cisco CSR"
Metadata:
"AWS::CloudFormation::Interface":
ParameterGroups:
- Label:
default: "VPC Parameters"
Parameters:
- AvailabilityZoneA
- AvailabilityZoneB
Parameters:
# ParentStack:
# Description: "Name of the CFN Stack for VPCs"
# : String
# Default: "OCTANK"
KeyPair:
Description: "Keypair to access the CSR"
Type: "AWS::EC2::KeyPair::KeyName"
Default: "whchoi02"
RouterChoice:
Description: Virtual Routers for the Virtual DC CGW
Default: Cisco
: String
AllowedValues:
- Cisco
Conditions:
CreateCiscoCSR: !Equals [ !Ref RouterChoice, Cisco ]
Mappings:
# AMI for Cisco CSR1kv
RegionMap:
'ap-northeast-2':
CSRAMI: "ami-0bfd6b68306c37acd"
'ap-northeast-1':
CSRAMI: "ami-0a32b4f1b6dbf76e2"
'us-east-1':
CSRAMI: "ami-0fc7a3d5400f4619d"
'us-east-2':
CSRAMI: "ami-0fda690c9c2f5cbf9"
Resources:
# Customer Gateway for TGW to DOCTANK Connectivity
CiscoCustomerGateway:
Condition: CreateCiscoCSR
: AWS::EC2::CustomerGateway
DependsOn: CSRIP
Properties:
BgpAsn: 65001
IpAddress: !Ref CSRIP
Tags:
- Key: Name
Value: DOCTANK-CGW
: ipsec.1
# CSRVPN Router in the Datacenter
CSRIP:
Condition: CreateCiscoCSR
: "AWS::EC2::EIP"
Properties:
Domain: vpc
ServerRole:
: AWS::IAM::Role
Properties:
RoleName: !Join ["-", [DOCTANK, Ref: "AWS::StackName", "SSMRole"]]
Path: "/"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
InstanceProfile:
: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles:
- !Ref ServerRole
CSRSecGroup:
Condition: CreateCiscoCSR
: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Open-up ports for local VPC and SSH
GroupName: CSR-SG
VpcId:
Fn::ImportValue: !Sub "DOCTANK-VPC"
SecurityGroupIngress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: "22"
ToPort: "22"
CidrIp: 0.0.0.0/0
CSRENI:
Condition: CreateCiscoCSR
: AWS::EC2::NetworkInterface
Properties:
SubnetId:
Fn::ImportValue: !Sub "DOCTANK-PublicSubnetA"
Description: Interface for controlling traffic such as SSH
GroupSet:
- Ref: CSRSecGroup
SourceDestCheck: false
Tags:
- Key: Name
Value: CSR
CSRInstance:
Condition: CreateCiscoCSR
: AWS::EC2::Instance
Properties:
NetworkInterfaces:
- NetworkInterfaceId: !Ref CSRENI
DeviceIndex: 0
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", CSRAMI]
Instance: c5.large
KeyName: !Ref KeyPair
IamInstanceProfile:
Ref: InstanceProfile
Tags:
- Key: Name
Value: DOCTANK-CSR
AssociateCSREIP:
Condition: CreateCiscoCSR
Type: AWS::EC2::EIPAssociation
Properties:
AllocationId: !GetAtt CSRIP.AllocationId
NetworkInterfaceId: !Ref CSRENI
PrivateDefaultRoute:
Condition: CreateCiscoCSR
Type: AWS::EC2::Route
DependsOn: CSRENI
Properties:
RouteTableId:
Fn::ImportValue: !Sub "DOCTANK-Private-Route-Table"
DestinationCidrBlock: 10.0.0.0/8
NetworkInterfaceId:
Ref: CSRENI
# Create NAT Gateway for BindServer To Get out to Internet
DOCTANKNATEIP:
: "AWS::EC2::EIP"
Properties:
Domain: vpc
DOCTANKNATGateway:
: "AWS::EC2::NatGateway"
Properties:
AllocationId:
Fn::GetAtt:
- DOCTANKNATEIP
- AllocationId
SubnetId:
Fn::ImportValue: !Sub "DOCTANK-PublicSubnetA"
Tags:
- Key: Name
Value: DOCTANK-NATGW
PrivateDefaultRoute:
: AWS::EC2::Route
DependsOn: DOCTANKNATGateway
Properties:
RouteTableId:
Fn::ImportValue: DOCTANK-Private-Route-Table
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId:
Ref: DOCTANKNATGateway
PrivateAWSRoute:
Condition: CreateCiscoCSR
: AWS::EC2::Route
DependsOn: CSRENI
Properties:
RouteTableId:
Fn::ImportValue: DOCTANK-Private-Route-Table
DestinationCidrBlock: 10.0.0.0/8
NetworkInterfaceId:
Ref: CSRENI
PublicAWSRoute:
Condition: CreateCiscoCSR
: AWS::EC2::Route
DependsOn: CSRENI
Properties:
RouteTableId:
Fn::ImportValue: DOCTANK-Public-Route-Table
DestinationCidrBlock: 10.0.0.0/8
NetworkInterfaceId:
Ref: CSRENI
Outputs:
# Datacenter 1 Outputs
CSRSSH:
Condition: CreateCiscoCSR
Description: "ssh command to CSR"
Value:
!Join [
"",
["ssh -i ~/.ssh/", Ref: "KeyPair", ".pem ec2-user@", !GetAtt "CSRENI.PrimaryPrivateIpAddress"],
]
Export:
Name: !Sub "DOCTANK-CSRssh"