-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfn-step2.yml
177 lines (176 loc) · 4.33 KB
/
cfn-step2.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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: DevOps Interview Challenge - Second Step
Parameters :
LatestAmiId :
Type : 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t3.micro
AllowedValues: [t1.micro, t2.micro, t3.micro]
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
CidrBlock: 10.0.0.0/16
Tags:
-
Key: 'Name'
Value: 'DevOps Interview Challenge'
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId:
Ref: VPC
CidrBlock: 10.0.0.0/24
Tags:
-
Key: 'Name'
Value: 'DevOps Interview Challenge'
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
-
Key: 'Name'
Value: 'DevOps Interview Challenge'
VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId:
Ref: VPC
InternetGatewayId:
Ref: InternetGateway
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId:
Ref: VPC
PublicNetworkAcl:
Type: "AWS::EC2::NetworkAcl"
Properties:
VpcId:
Ref: "VPC"
PublicNACLEntryEgress100:
Type: AWS::EC2::NetworkAclEntry
Properties:
CidrBlock: '0.0.0.0/0'
NetworkAclId:
Ref: PublicNetworkAcl
Egress: 'true'
PortRange:
From: '80'
To: '80'
Protocol: '6'
RuleAction: Allow
RuleNumber: 100
PublicNACLEntryIngress110:
Type: AWS::EC2::NetworkAclEntry
Properties:
CidrBlock: '10.0.0.0/0'
NetworkAclId:
Ref: PublicNetworkAcl
Egress: 'false'
PortRange:
From: '80'
To: '80'
Protocol: 17
RuleAction: Allow
RuleNumber: 110
PublicNACLEntryIngress100:
Type: AWS::EC2::NetworkAclEntry
Properties:
CidrBlock: '0.0.0.0/0'
NetworkAclId:
Ref: PublicNetworkAcl
Egress: 'false'
PortRange:
From: '80'
To: '80'
Protocol: -1
RuleAction: Deny
RuleNumber: 100
PublicRoute:
Type: AWS::EC2::Route
DependsOn: VPCGatewayAttachment
Properties:
RouteTableId:
Ref: PublicRouteTable
DestinationCidrBlock: 10.1.0.0/16
GatewayId:
Ref: InternetGateway
PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId:
Ref: PublicSubnet
RouteTableId:
Ref: PublicRouteTable
PublicSubnetNetworkAclAssociation:
Type: AWS::EC2::SubnetNetworkAclAssociation
Properties:
SubnetId:
Ref: PublicSubnet
NetworkAclId:
Ref: PublicNetworkAcl
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: HTTP ingress
VpcId:
Ref: VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 10.0.0.0/16
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 10.0.0.0/16
Tags:
-
Key: 'Name'
Value: 'DevOps Interview Challenge'
WebServerInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref 'InstanceType'
ImageId: !Ref LatestAmiId
KeyName: "interview1"
NetworkInterfaces:
- GroupSet:
- Ref: WebServerSecurityGroup
AssociatePublicIpAddress: 'false'
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId:
Ref: PublicSubnet
Tags:
-
Key: 'Name'
Value: 'DevOps Interview Challenge'
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
sudo yum update -y
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
echo "<html><body><p><h1 align=center>DevOps Interview Challenge!</h1></body></html>" > /var/www/html/index.html
EIP:
Type: AWS::EC2::EIP
Properties:
Domain: vpc
InstanceId:
Ref: WebServerInstance
Outputs:
FQDN:
Value: !GetAtt WebServerInstance.PublicDnsName
Note:
Value: 'Mistake was made!'