forked from aws-samples/ecs-refarch-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaster-spot.yaml
245 lines (211 loc) · 8.84 KB
/
master-spot.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
Description: >
This template deploys a highly available ECS cluster using an AutoScaling Group, with
ECS hosts distributed across multiple Availability Zones.
Last Modified: 06th May 2020
File: master-spot.yaml
Authors:
- Marcelo Manzan <marcelo.manzan@truckpad.com.br>
- Marcos Sobrinho <marcos.sobrinho@truckpad.com.br>
- Paul Maddox <pmaddox@amazon.com>
Parameters:
MinClusterSize:
Description: How many ECS hosts do you want to initially deploy?
Type: Number
Default: 2
MaxClusterSize:
Description: How many ECS hosts do you want this cluster to have at most?
Type: Number
Default: 4
SpotInstanceType1:
Description: Instance type to use when Instance Lifecycle is "spot"
Type: String
AllowedValues: [c3.large, c3.xlarge, c3.2xlarge, m3.large, m3.xlarge, m3.2xlarge, c4.large, c4.xlarge, c4.2xlarge, m4.large, m4.xlarge, m4.2xlarge]
Default: 'c3.large'
SpotInstanceType2:
Description: Instance type to use when Instance Lifecycle is "spot"
Type: String
AllowedValues: [c3.large, c3.xlarge, c3.2xlarge, m3.large, m3.xlarge, m3.2xlarge, c4.large, c4.xlarge, c4.2xlarge, m4.large, m4.xlarge, m4.2xlarge]
Default: 'c4.large'
SpotInstanceType3:
Description: Instance type to use when Instance Lifecycle is "spot"
Type: String
AllowedValues: [c3.large, c3.xlarge, c3.2xlarge, m3.large, m3.xlarge, m3.2xlarge, c4.large, c4.xlarge, c4.2xlarge, m4.large, m4.xlarge, m4.2xlarge]
Default: 'm4.large'
SpotMaximumPrice:
Description: Maximum bid value for Spot Instances
Type: Number
Default: 0.10
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the ECS cluster
Type: AWS::EC2::KeyPair::KeyName
VPCToAttach:
Description: 'Choose an existing exported VPC name to use *OR*'
Type: String
SubnetPrefix:
Description: >
To create a new VPC. IP address first two blocks, used to build the new VPC Subnet IPs.
Should be within the Private IPv4 address space and shouldn't be already in use by another
VPC or Subnet
Type: String
Default: '10.16'
AllowedPattern: ^(10|172|192)\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
DatadogApiKey:
Description: Install Datadog dd-agent using this API Key. Let empty to disable
Type: String
AllowedPattern: ^|[a-f0-9]{32}$
DatadogEnableAPM:
Description: Enable Application Performance Monitoring (trace). Only used if you have an valid Datadog API Key.
Type: String
Default: false
AllowedValues: [false, true]
DeviceName:
Description: The name of the device within the EC2 instance, such as /dev/dsh or xvdh.
Type: String
Default: "/dev/xvda"
VolumeSize:
Description: Disk volume size (GiB's) of the EC2 instances
Type: Number
Default: 10
AMIBaseId:
Description: The AWS AMI base to use
Type: AWS::EC2::Image::Id
Default: ''
ApplyResources:
Description: Let the VPN server up and Running
Type: String
Default: 'no'
AllowedValues: ['no', 'yes']
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: ECS Cluster
Parameters:
- MinClusterSize
- MaxClusterSize
- Label:
default: ECS Cluster - Spot
Parameters:
- SpotInstanceType1
- SpotInstanceType2
- SpotInstanceType3
- SpotMaximumPrice
- DeviceName
- VolumeSize
- AMIBaseId
- Label:
default: Networking
Parameters:
- KeyName
- VPCToAttach
- SubnetPrefix
- Label:
default: Application Monitoring
Parameters:
- DatadogApiKey
- DatadogEnableAPM
ParameterLabels:
MinClusterSize:
default: Minimal Cluster Size
MaxClusterSize:
default: Maximum Cluster Size
SpotInstanceType1:
default: 'Spot Instance Type #1'
SpotInstanceType2:
default: 'Spot Instance Type #2'
SpotInstanceType3:
default: 'Spot Instance Type #3'
SpotMaximumPrice:
default: Spot Maximum Price
ShouldCreateVPC:
default: Create or attach to VPC?
VPCToAttach:
default: Existing VPC to attach
SubnetPrefix:
default: Subnet Prefix for New VPC
KeyName:
default: SSH Key Name
DatadogApiKey:
default: Datadog API Key
DatadogEnableAPM:
default: 'Datadog: Enable APM?'
DeviceName:
default: Device Name
VolumeSize:
default: EC2 Volume Size
AMIBaseId:
default: AMI Base Id
Conditions:
ShouldApplyResource: !Equals [ !Ref ApplyResources, 'yes' ]
EnableDatadogAgent: !And [ !Equals [ !Ref ApplyResources, 'yes' ], !Not [ !Equals [ !Ref DatadogApiKey, '' ] ] ]
ShouldCreateVPC: !And [ !Equals [ !Ref ApplyResources, 'yes' ], !Equals [ !Ref VPCToAttach, '' ] ]
Resources:
vpc:
Type: AWS::CloudFormation::Stack
Condition: ShouldCreateVPC
Properties:
TemplateURL: https://s3.amazonaws.com/cfn-truckpad/ecs/infrastructure/vpc.yaml
Parameters:
EnvironmentName: !Ref AWS::StackName
VpcCIDR: !Join ['.', [!Ref SubnetPrefix, '0.0/16']]
PublicSubnet1CIDR: !Join ['.', [!Ref SubnetPrefix, '8.0/21']]
PublicSubnet2CIDR: !Join ['.', [!Ref SubnetPrefix, '16.0/21']]
PrivateSubnet1CIDR: !Join ['.', [!Ref SubnetPrefix, '24.0/21']]
PrivateSubnet2CIDR: !Join ['.', [!Ref SubnetPrefix, '32.0/21']]
sgs:
Type: AWS::CloudFormation::Stack
Condition: ShouldApplyResource
Properties:
TemplateURL: https://s3.amazonaws.com/cfn-truckpad/ecs/infrastructure/security-groups.yaml
Parameters:
EnvironmentName: !Ref AWS::StackName
VPC: !If [ShouldCreateVPC, !GetAtt vpc.Outputs.VPC, {'Fn::ImportValue': !Sub '${VPCToAttach}'}]
ecs:
Type: AWS::CloudFormation::Stack
Condition: ShouldApplyResource
Properties:
TemplateURL: !Sub https://s3.amazonaws.com/cfn-truckpad/ecs/infrastructure/ecs-cluster-spot.yaml
Parameters:
EnvironmentName: !Ref AWS::StackName
KeyName: !Ref KeyName
InstanceType1: !Ref SpotInstanceType1
InstanceType2: !Ref SpotInstanceType2
InstanceType3: !Ref SpotInstanceType3
MaximumPrice: !Ref SpotMaximumPrice
MinClusterSize: !Ref MinClusterSize
MaxClusterSize: !Ref MaxClusterSize
VPC: !If [ShouldCreateVPC, !GetAtt vpc.Outputs.VPC, {'Fn::ImportValue': !Sub '${VPCToAttach}'}]
SecurityGroup: !GetAtt sgs.Outputs.ECSHostSecurityGroup
Subnets: !If [ShouldCreateVPC, !GetAtt vpc.Outputs.PrivateSubnets, {'Fn::ImportValue': !Sub '${VPCToAttach}-private-subnets'}]
DeviceName: !Ref DeviceName
VolumeSize: !Ref VolumeSize
AMIBaseId: !Ref AMIBaseId
ddagent:
Type: AWS::CloudFormation::Stack
Condition: EnableDatadogAgent
DependsOn: ecs
Properties:
TemplateURL: https://s3.amazonaws.com/cfn-truckpad/ecs/services/dd-agent/service.yaml
Parameters:
Cluster: !Ref AWS::StackName
ApiKey: !Ref DatadogApiKey
EnableAPM: !Ref DatadogEnableAPM
Outputs:
LoadBalancerSecurityGroup:
Description: A reference to the security group for load balancers
Condition: ShouldApplyResource
Value: !GetAtt sgs.Outputs.LoadBalancerSecurityGroup
Export:
Name: !Sub ${AWS::StackName}-alb-sgs
VPC:
Description: VPC ARN
Condition: ShouldApplyResource
Value: !If [ShouldCreateVPC, !GetAtt vpc.Outputs.VPC, {'Fn::ImportValue': !Sub '${VPCToAttach}'}]
Export:
Name: !Sub ${AWS::StackName}-vpc
PublicSubnets:
Description: VPC Public Subnets
Condition: ShouldApplyResource
Value: !If [ShouldCreateVPC, !GetAtt vpc.Outputs.PublicSubnets, {'Fn::ImportValue': !Sub '${VPCToAttach}-public-subnets'}]
Export:
Name: !Sub ${AWS::StackName}-vpc-public-subnets