-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathelb.ts
90 lines (75 loc) · 2.05 KB
/
elb.ts
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
import * as _ from 'lodash';
import { Cluster } from './cluster'
import { Resource } from './resource'
export class ELB implements Resource {
cluster: Cluster
private PORTS: { [protocol: string]: number; } = {
'HTTP': 80,
'HTTPS': 443,
}
constructor(cluster: Cluster) {
this.cluster = cluster;
}
get name() {
return 'ELB';
}
generate() {
let definition:any = {
'ClsELB': {
'Type': 'AWS::ElasticLoadBalancingV2::LoadBalancer',
'Properties': {
'Scheme': 'internet-facing',
'LoadBalancerAttributes': [
{
'Key': 'idle_timeout.timeout_seconds',
'Value': 30
}
],
'Subnets': this.cluster.subnets,
'SecurityGroups': [this.cluster.securityGroup]
}
}
}
let listeners:Array<any> = _.map(this.cluster.protocol, (protocol) => {
return this.generateListener(protocol)
})
return _.assign(definition, ...listeners);
}
generateListener(protocol: string) {
let definition:any = {
[`Cls${protocol}Listener`]: {
'Type': 'AWS::ElasticLoadBalancingV2::Listener',
"DependsOn": 'ClsELB',
'Properties': {
'Certificates': [],
'DefaultActions': [
{
'Type': 'forward',
'TargetGroupArn': {
'Ref': `Cls${protocol}TargetGroup`
}
}
],
'LoadBalancerArn': {
'Ref': 'ClsELB'
},
'Port': this.PORTS[protocol],
'Protocol': protocol
}
},
[`Cls${protocol}TargetGroup`]: {
'Type': 'AWS::ElasticLoadBalancingV2::TargetGroup',
'DependsOn': 'ClsELB',
'Properties': {
'Port': this.PORTS[protocol],
'Protocol': protocol,
'VpcId': this.cluster.vpcId
}
}
}
if (protocol == 'HTTPS') {
definition[`Cls${protocol}Listener`].Properties.Certificates = [{'CertificateArn': this.cluster.certificate}]
}
return definition;
}
}