-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc_v11.yaml
206 lines (184 loc) · 5.61 KB
/
vpc_v11.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
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
Description:
This template creates one VPC and two subnets. Each subnet belongs to one AvailabilityZone. (v1)
It also creates an InternetGateway and attaches is to the VPC. (v2)
Also creates a route table, than a route (0.0.0.0/0) pointing at the InternetGateway. In the end associates the subnets to the route table (v3)
Adding an Instance in the first subnet. Creating a SG allowing SSH from 0/0. Assign SG to previous Instance (v4)
Adding UserData and changing ROOT Volume /dev/xvda (v5)
Adding a second Volume using mappings (v6)
Adding a third Volume using Volumes (v7)
Adding a forth Volume using VolumeAttachment (v8)
Adding Subnets for a LB (v9)
Adding a Classic LB (_Note_ The previously added subnets have no route table association, the LB has no security group and the instance SG doesn't allow http (v10)
Permitting the LB subnets access in the Instance SG on port 80 - requests from LB being seen with tcpdump (v11)
Parameters:
VpcCidrBlock:
Type: String
Default: "10.100.0.0/16"
Description: "Input the VPC CIDR Block"
Subnet1CidrBlock:
Type: String
Default: "10.100.1.0/24"
Description: "Subnet 1 CIDR Block"
Subnet2CidrBlock:
Type: String
Default: "10.100.2.0/24"
Description: "Subnet 2 CIDR Block"
LBsubnet1CidrBlock:
Type: String
Default: "10.100.10.0/24"
Description: "LoadBalancer Subnet 1 CIDR Block"
LBsubnet2CidrBlock:
Type: String
Default: "10.100.20.0/24"
Description: "LoadBalancer Subnet 2 CIDR Block"
Resources:
GabiVPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: !Ref VpcCidrBlock
MyInternetGateway:
Type: "AWS::EC2::InternetGateway"
# Create the InternetGateway
IntGw2VPCconnection:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
InternetGatewayId: !Ref MyInternetGateway
VpcId: !Ref GabiVPC
# Connect the VPC and the InternetGateway
Subnet1:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref GabiVPC
CidrBlock: !Ref Subnet1CidrBlock
MapPublicIpOnLaunch: True
AvailabilityZone: !Select [0, !GetAZs ]
# Fn::Select:
# - 0
# - Fn::GetAZs: ""
Subnet2:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref GabiVPC
CidrBlock: !Ref Subnet2CidrBlock
MapPublicIpOnLaunch: True
AvailabilityZone: !Select [1, !GetAZs ]
LBSubnet1:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref GabiVPC
CidrBlock: !Ref LBsubnet1CidrBlock
MapPublicIpOnLaunch: True
AvailabilityZone: !Select [0, !GetAZs ]
LBSubnet2:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: !Ref GabiVPC
CidrBlock: !Ref LBsubnet2CidrBlock
MapPublicIpOnLaunch: True
AvailabilityZone: !Select [1, !GetAZs ]
MyRouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref GabiVPC
MyDefaultRoute:
Type: "AWS::EC2::Route"
Properties:
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref MyInternetGateway
RouteTableId: !Ref MyRouteTable
Subnet1RouteTblAssoc:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId: !Ref MyRouteTable
SubnetId: !Ref Subnet1
Subnet2RouteTblAssoc:
Type: "AWS::EC2::SubnetRouteTableAssociation"
Properties:
RouteTableId: !Ref MyRouteTable
SubnetId: !Ref Subnet2
Instance01SG:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Allows SSH from everywhere"
VpcId: !Ref GabiVPC
SecurityGroupIngress:
- IpProtocol: "tcp"
CidrIp: "0.0.0.0/0"
FromPort: 22
ToPort: 22
- IpProtocol: "tcp"
CidrIp: !Ref LBsubnet1CidrBlock
FromPort: 80
ToPort: 80
- IpProtocol: "tcp"
CidrIp: !Ref LBsubnet1CidrBlock
FromPort: 80
ToPort: 80
Instance01:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: !Select [ 0, !GetAZs ]
SubnetId: !Ref Subnet1
ImageId: "ami-a4c7edb2"
InstanceType: "t2.micro"
KeyName: "gabi-nvirginia"
SecurityGroupIds:
- !Ref Instance01SG
UserData:
Fn::Base64: |
#!/bin/bash
/bin/echo "dadada" > /gabi
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
VolumeType: "gp2"
VolumeSize: "20"
- DeviceName: "/dev/xvdc"
Ebs:
VolumeType: "gp2"
VolumeSize: "10"
Volumes:
- Device: "/dev/xvdd"
VolumeId: !Ref GabisVolume
GabisVolume:
Type: "AWS::EC2::Volume"
Properties:
AvailabilityZone: !Select [ 0, !GetAZs ]
Size: "15"
VolumeType: "gp2"
Gabis2ndVolume:
Type: "AWS::EC2::Volume"
Properties:
#AvailabilityZone: !Select [ 0, !GetAZs ]
AvailabilityZone: !GetAtt Instance01.AvailabilityZone
Size: "5"
VolumeType: "gp2"
Gabis2ndVolumeAttachment:
Type: "AWS::EC2::VolumeAttachment"
Properties:
Device: "/dev/xvdf"
InstanceId: !Ref Instance01
VolumeId: !Ref Gabis2ndVolume
GabisClassicLB:
Type: "AWS::ElasticLoadBalancing::LoadBalancer"
Properties:
ConnectionDrainingPolicy:
Enabled: True
Timeout: "60"
CrossZone: True
HealthCheck:
HealthyThreshold: "10"
Interval: "30"
Target: "HTTP:80/index.html"
Timeout: "5"
UnhealthyThreshold: "10"
Listeners:
- InstancePort: "80"
InstanceProtocol: "HTTP"
LoadBalancerPort: "80"
Protocol: "HTTP"
Instances:
- !Ref Instance01
Subnets:
- !Ref LBSubnet1
- !Ref LBSubnet2