@@ -2,8 +2,7 @@ import { CfnAutoScalingGroup } from '@aws-cdk/aws-autoscaling';
2
2
import { EbsDeviceVolumeType } from '@aws-cdk/aws-ec2' ;
3
3
import { Effect , PolicyStatement , Role , ServicePrincipal } from '@aws-cdk/aws-iam' ;
4
4
import { Construct } from '@aws-cdk/core' ;
5
- import { InternalSG } from '..' ;
6
- import { AutoScaler , IngressRule , InternalRole } from './autoScalingGroup' ;
5
+ import { AutoScaler , IngressRule , NetworkProps , InternalSG , TargetGroupProps , InternalRole } from './autoScalingGroup' ;
7
6
import { Deployment } from './deployment' ;
8
7
import { BalancerEntry } from './network' ;
9
8
@@ -15,24 +14,19 @@ export interface MicroServiceProps {
15
14
readonly asgMaxSize ?: string ;
16
15
readonly asgMinSize ?: string ;
17
16
readonly instanceLabels ?: CfnAutoScalingGroup . TagPropertyProperty [ ] ;
18
- readonly healthCheckPath ?: string ;
19
- readonly port ?: number ;
20
17
readonly vpc : string ;
21
18
readonly subnets : string [ ] ;
22
- readonly protocol ?: string ;
23
19
readonly diskSize ?: number ;
24
20
readonly role : InternalRole ;
25
21
readonly tcpRules ?: IngressRule [ ] ;
26
- readonly sslEnabled ?: boolean ;
27
- readonly host ?: string ;
28
- readonly lbArn ?: string ;
29
22
readonly ami ?: string ;
30
23
readonly sshKey : string ;
31
24
readonly diskType ?: string ;
32
25
readonly createCodedeployApplication ?: boolean ;
33
26
readonly deploymentPolicies ?: string [ ] ;
34
27
readonly applicationType ?: string ;
35
28
readonly securityGroupProps ?: InternalSG ;
29
+ readonly networkProps ?: NetworkProps [ ] ;
36
30
}
37
31
export class MicroService extends Construct {
38
32
@@ -42,23 +36,19 @@ export class MicroService extends Construct {
42
36
public readonly asgMinSize ?: string ;
43
37
public readonly env ?: string ;
44
38
public readonly instanceLabels ?: CfnAutoScalingGroup . TagPropertyProperty [ ] ;
45
- public readonly healthCheckPath ?: string ;
46
- public readonly port ?: number ;
47
- public readonly protocol ?: string ;
48
39
public readonly diskSize ?: number ;
49
40
public readonly vpc : string ;
50
41
public readonly role : InternalRole ;
51
42
public readonly tcpRules ?: IngressRule [ ] ;
52
43
public readonly subnets : string [ ] ;
53
- public readonly sslEnabled ?: boolean ;
54
- public readonly host ?: string ;
55
- public readonly lbArn ?: string ;
56
44
public readonly sshKey : string ;
57
45
public readonly diskType ?: string ;
58
46
public readonly createCodedeployApplication ?: boolean ;
59
47
public readonly deploymentPolicies ?: string [ ] ;
60
48
public readonly applicationType ?: string ;
61
49
public readonly securityGroupProps ?: InternalSG ;
50
+ public readonly networkProps ?: NetworkProps [ ] ;
51
+ public readonly targetGroupProps : TargetGroupProps [ ] ;
62
52
63
53
constructor ( scope : Construct , id : string , props : MicroServiceProps ) {
64
54
super ( scope , id ) ;
@@ -69,38 +59,28 @@ export class MicroService extends Construct {
69
59
this . asgMinSize = props ?. asgMinSize ?? '1' ;
70
60
this . env = props ?. env ?? 'development' ;
71
61
this . instanceLabels = props ?. instanceLabels ;
72
- this . healthCheckPath = props ?. healthCheckPath ?? '/v1/healthCheck' ;
73
- this . port = props . port ?? undefined ;
74
- this . protocol = props . protocol ?? 'HTTP' ;
75
62
this . diskSize = props . diskSize ?? 8 ;
76
63
this . vpc = props . vpc ;
77
64
this . role = props . role ;
78
65
this . tcpRules = props . tcpRules ?? [ ] ;
79
66
this . subnets = props . subnets ;
80
- this . sslEnabled = props . sslEnabled ;
81
- this . host = props . host ;
82
- this . lbArn = props . lbArn ;
83
67
this . sshKey = props . sshKey ;
84
68
this . diskType = props . diskType ;
85
69
this . createCodedeployApplication = props . createCodedeployApplication ?? false ;
86
70
this . deploymentPolicies = props . deploymentPolicies ?? [ ] ;
87
71
this . applicationType = props . applicationType ?? 'new' ;
88
72
this . securityGroupProps = props . securityGroupProps ;
73
+ this . networkProps = props . networkProps ?? [ ] ;
74
+ this . targetGroupProps = [ ] ;
75
+ this . networkProps = props . networkProps ?? [ ] ;
89
76
90
77
const resourceNamePrefix = this . env + '-' + this . appName ;
91
78
const asg = new AutoScaler ( this , resourceNamePrefix + '-as' , {
92
79
asgName : resourceNamePrefix + '-ASG' ,
80
+ appName : resourceNamePrefix ,
81
+ networkProps : this . networkProps ,
93
82
maxSize : this . asgMaxSize ,
94
83
minSize : this . asgMinSize ,
95
- tgProps : this . port ? {
96
- type : 'new' ,
97
- healthPath : this . healthCheckPath ,
98
- protocol : this . protocol ,
99
- port : this . port ,
100
- name : ( ( resourceNamePrefix + '-TG' ) . length >= 32 ) ? this . env + '-' + this . appName + '-TG' :resourceNamePrefix + '-TG' ,
101
- timeout : 10 ,
102
- thresholdCount : 2 ,
103
- } : undefined ,
104
84
templateProps : {
105
85
instanceType : this . instanceType ,
106
86
detailedMonitoring : false ,
@@ -144,17 +124,14 @@ export class MicroService extends Construct {
144
124
tgName : resourceNamePrefix + '-TG' ,
145
125
} ) ;
146
126
dep . node . addDependency ( depRole ) ;
127
+ dep . node . addDependency ( asg ) ;
147
128
}
148
129
149
- if ( this . host && this . lbArn && asg . targetGroupArn != '' ) {
150
- const lbEntry = new BalancerEntry ( this , resourceNamePrefix + '-lb' , {
151
- appName : this . appName ,
152
- hostHeader : this . host ,
153
- targetGroupArn : asg . targetGroupArn ,
154
- lbArn : this . lbArn ,
155
- sslEnabled : this . sslEnabled ?? false ,
130
+ if ( this . networkProps . length ) {
131
+ asg . loadBalancerProperties ?. forEach ( lbProp => {
132
+ const lbEntry = new BalancerEntry ( this , lbProp . hostHeader , lbProp ) ;
133
+ lbEntry . node . addDependency ( asg ) ;
156
134
} ) ;
157
- lbEntry . node . addDependency ( asg ) ;
158
135
}
159
136
}
160
137
0 commit comments