-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_template.yml
200 lines (197 loc) · 5.6 KB
/
app_template.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
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation Sample Template Sample template EIP_With_Association: This
template shows how to associate an Elastic IP address with an Amazon EC2
instance - you can use this same technique to associate an EC2 instance with
an Elastic IP Address that is not created inside the template by replacing the
EIP reference in the AWS::EC2::EIPAssoication resource type with the IP
address of the external EIP. **WARNING** This template creates an Amazon EC2
instance and an Elastic IP Address. You will be billed for the AWS resources
used if you create a stack from this template.
Parameters:
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.small
AllowedValues:
- t1.micro
- t2.nano
- t2.micro
- t2.small
- t2.medium
- t2.large
- m1.small
- m1.medium
- m1.large
- m1.xlarge
- m2.xlarge
- m2.2xlarge
- m2.4xlarge
- m3.medium
- m3.large
- m3.xlarge
- m3.2xlarge
- m4.large
- m4.xlarge
- m4.2xlarge
- m4.4xlarge
- m4.10xlarge
- c1.medium
- c1.xlarge
- c3.large
- c3.xlarge
- c3.2xlarge
- c3.4xlarge
- c3.8xlarge
- c4.large
- c4.xlarge
- c4.2xlarge
- c4.4xlarge
- c4.8xlarge
- g2.2xlarge
- g2.8xlarge
- r3.large
- r3.xlarge
- r3.2xlarge
- r3.4xlarge
- r3.8xlarge
- i2.xlarge
- i2.2xlarge
- i2.4xlarge
- i2.8xlarge
- d2.xlarge
- d2.2xlarge
- d2.4xlarge
- d2.8xlarge
- hi1.4xlarge
- hs1.8xlarge
- cr1.8xlarge
- cc2.8xlarge
- cg1.4xlarge
ConstraintDescription: must be a valid EC2 instance type.
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: 'AWS::EC2::KeyPair::KeyName'
ConstraintDescription: must be the name of an existing EC2 KeyPair.
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
Type: String
MinLength: '9'
MaxLength: '18'
Default: 0.0.0.0/0
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
ImageId:
Description: Name of image to spin with
Type: String
ConstraintDescription: must be the name of an existing Image ID.
NetworkStack:
Description: Name of Network stack layer
Type: String
Resources:
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access
VpcId:
Fn::ImportValue: !Sub ${NetworkStack}-VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: !Ref SSHLocation
ApplicationSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access
VpcId:
Fn::ImportValue: !Sub ${NetworkStack}-VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '8085'
ToPort: '8085'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '54663'
ToPort: '54663'
CidrIp: 0.0.0.0/0
LoadBalancerSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable HTTPS Access to LB
VpcId:
Fn::ImportValue: !Sub ${NetworkStack}-VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '443'
ToPort: '443'
CidrIp: 0.0.0.0/0
EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
ImageId: !Ref ImageId
SecurityGroupIds:
- !Ref InstanceSecurityGroup
- !Ref ApplicationSecurityGroup
SubnetId:
Fn::ImportValue: !Sub ${NetworkStack}-PublicSubnet1
Tags:
-
Key: "Name"
Value: "conference-bamboo-with-loadbalancer-master-backup"
IPAddress:
Type: 'AWS::EC2::EIP'
IPAssoc:
Type: 'AWS::EC2::EIPAssociation'
Properties:
InstanceId: !Ref EC2Instance
EIP: !Ref IPAddress
ALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
IpAddressType: ipv4
Name: "conference-bamboo-lb-backup"
Scheme: internet-facing
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
Subnets:
- Fn::ImportValue: !Sub ${NetworkStack}-PublicSubnet1
- Fn::ImportValue: !Sub ${NetworkStack}-PublicSubnet2
Type: application
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: "conference-bamboo-tg-backup"
Port: 8085
Protocol: HTTP
Targets:
- Id: !Ref EC2Instance
Port: 8085
TargetType: instance
Matcher:
HttpCode: '302,200'
VpcId:
Fn::ImportValue: !Sub ${NetworkStack}-VpcId
ALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
Certificates:
- CertificateArn: "arn:aws:acm:ap-southeast-1:667871478305:certificate/d852785b-0b13-4d38-98c5-f11ac5a56806"
DefaultActions:
- TargetGroupArn: !Ref TargetGroup
Type: forward
LoadBalancerArn: !Ref ALB
Port: 443
Protocol: "HTTPS"
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref EC2Instance
InstanceIPAddress:
Description: IP address of the newly created EC2 instance
Value: !Ref IPAddress
LBDNSNAme:
Description: DNS Name of LB
Value: !GetAtt ALB.DNSName