-
Notifications
You must be signed in to change notification settings - Fork 2
/
Master-Stack.yaml
179 lines (179 loc) · 5.39 KB
/
Master-Stack.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
AWSTemplateFormatVersion: 2010-09-09
Description: Master template that includes nested templates
Parameters:
S3BucketName:
Description: 'Name of the S3 bucket in which zip file for Custom Resource Lambda is located.'
Type: String
Default: MyCloudFormationTemplates
S3Key:
Description: 'S3 key where the Lambda zip file in above bucket is located for Lambda Custom Resource.'
Type: String
Default: 'Repo_CFN_Templates/ECS_Capacity_Provider_Factory.zip'
FileLocation:
Description: 'URL where all the yaml file has been saved (without the .yaml file name).'
Type: String
Default: 'https://s3.amazonaws.com/MyCloudFormationTemplates/Repo_CFN_Templates/'
DockerImage:
Description: 'Docker Image using which ECS Service Will be created.'
Type: String
Default: 'santosham2007s/ec2-instance-info:v1'
ECSSSHKeyName:
Description: 'The Key Pair to allow SSH access to the instances'
Type: AWS::EC2::KeyPair::KeyName
Default: MainPubKey
Resources:
VpcStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'VPC_PubPriSubnet_2AZ.yaml']]
TimeoutInMinutes: '5'
IamStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'IAM_Resources.yaml']]
TimeoutInMinutes: '5'
EcsClusterStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'ECSCluster_and_Role.yaml']]
TimeoutInMinutes: '5'
DependsOn: IamStack
EcsTDStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'ECS_Task_Definition.yaml']]
TimeoutInMinutes: '5'
Parameters:
DockerImageName: !Ref DockerImage
CloudWatchLogsGroup: !GetAtt
- EcsClusterStack
- Outputs.LogGroup
TaskRole: !GetAtt
- IamStack
- Outputs.ECSTaskRole
TaskExecutionRole: !GetAtt
- IamStack
- Outputs.ECSTaskExecutionRole
DependsOn: IamStack
DependsOn: EcsClusterStack
AlbStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'TG_and_ALB.yaml' ]]
TimeoutInMinutes: '5'
Parameters:
VPCId: !GetAtt
- VpcStack
- Outputs.VPC
SubnetIds: !Join
- ','
- - !GetAtt
- VpcStack
- Outputs.PublicSubnet1
- !GetAtt
- VpcStack
- Outputs.PublicSubnet2
ALBSecurityGroups: !Join
- ','
- - !GetAtt
- VpcStack
- Outputs.NoIngressSecurityGroup
- !GetAtt
- VpcStack
- Outputs.WebAccessSecurityGroup
DependsOn: VpcStack
AsgStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'ECS_ASG_Group.yaml' ]]
TimeoutInMinutes: '5'
Parameters:
ECSCluster: !GetAtt
- EcsClusterStack
- Outputs.ECSCluster
ECSInstanceProfile: !GetAtt
- IamStack
- Outputs.IAMInstanceProfile
TargetGroupARNs: !GetAtt
- AlbStack
- Outputs.TargetGroupARN
ASGSubnetIds: !Join
- ','
- - !GetAtt
- VpcStack
- Outputs.PublicSubnet1
- !GetAtt
- VpcStack
- Outputs.PublicSubnet2
LCSecurityGroups: !Join
- ','
- - !GetAtt
- VpcStack
- Outputs.NoIngressSecurityGroup
- !GetAtt
- VpcStack
- Outputs.WebAccessSecurityGroup
ECSKeyName: !Ref ECSSSHKeyName
DependsOn: AlbStack
DependsOn: EcsClusterStack
EcsAsgCPStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Join [ '', [ !Ref FileLocation, 'Custom_Resource_Capacity_Provider.yaml' ]]
TimeoutInMinutes: '5'
Parameters:
ASGName: !GetAtt
- AsgStack
- Outputs.ASGName
ECSClusterName: !GetAtt
- EcsClusterStack
- Outputs.ECSCluster
LambdaZipsBucket: !Ref S3BucketName
LambdaZipFunctionS3KeyPrefix: !Ref S3Key
ECSTaskDefinition: !GetAtt
- EcsTDStack
- Outputs.TaskDefinitionARN
ALBTargetGroupARN: !GetAtt
- AlbStack
- Outputs.TargetGroupARN
LambdaExecutionRole: !GetAtt
- IamStack
- Outputs.LambdaExecutionRole
DependsOn: AsgStack
DependsOn: EcsClusterStack
Outputs:
VpcId:
Description: 'VPC Name'
Value: !GetAtt
- VpcStack
- Outputs.VPC
LambdaFunction:
Description: 'Lambda Function Name'
Value: !GetAtt
- EcsAsgCPStack
- Outputs.LambdaFunction
CapacityProvider:
Description: 'Capacity Provider Name'
Value: !GetAtt
- EcsAsgCPStack
- Outputs.CapacityProvider
EcsServiceName:
Description: 'ECS Service Name'
Value: !GetAtt
- EcsAsgCPStack
- Outputs.ECSServiceName
AlbArn:
Description: 'ALB ARN'
Value: !GetAtt
- AlbStack
- Outputs.ALBARN
AlbDnsName:
Description: 'ALB DNS Name'
Value: !GetAtt
- AlbStack
- Outputs.ALBDNSName
EcsServiceScalingPolicy:
Description: 'ECS Service Scaling Policy ARN'
Value: !GetAtt
- EcsAsgCPStack
- Outputs.ECSServiceScalingPolicy