-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_seed.yml
360 lines (350 loc) · 12.3 KB
/
aws_seed.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
AWSTemplateFormatVersion: 2010-09-09
Parameters:
PipelineName:
Type: String
MaxLength: 54
MinLength: 4
AllowedPattern: ^[A-Za-z0-9][A-Za-z0-9\-]{2,52}[A-Za-z0-9]$
ConstraintDescription: "Must only contain alphanumeric or dashes (and cannot start or end with a dash)"
BucketPrefix:
Type: String
MaxLength: 39
MinLength: 3
AllowedPattern: ^[0-9a-z][0-9a-z\-]{1,37}[0-9a-z]$
BucketRegion:
Type: String
AllowedValues:
- 'ap-northeast-1'
- 'ap-northeast-2'
- 'ap-south-1'
- 'ap-southeast-1'
- 'ap-southeast-2'
- 'ca-central-1'
- 'eu-central-1'
- 'eu-north-1'
- 'eu-west-1'
- 'eu-west-2'
- 'eu-west-3'
- 'sa-east-1'
- 'us-east-1'
- 'us-east-2'
- 'us-west-1'
- 'us-west-2'
BucketSuffix:
Type: String
MaxLength: 9
MinLength: 1
Default: 'inception'
Resources:
CodeCommitRepository:
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
DependsOn:
- CloudFormationDeployActionRole
Type: 'AWS::CodeCommit::Repository'
Properties:
RepositoryName: !Ref PipelineName
RepositoryDescription: !Sub '${PipelineName} CodeCommit Repository'
CodePipelineBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName: !Sub '${BucketPrefix}-${BucketRegion}-${BucketSuffix}'
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
CloudFormationDeployActionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: ['sts:AssumeRole']
Effect: Allow
Principal:
Service: [cloudformation.amazonaws.com]
Version: '2012-10-17'
Path: /
Policies:
- PolicyName: CloudFormationRole
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- 'cloudformation:CreateStack'
- 'cloudformation:DeleteStack'
- 'cloudformation:DescribeStacks'
- 'codebuild:CreateProject'
- 'codebuild:DeleteProject'
- 'codecommit:CreateRepository'
- 'codecommit:DeleteRepository'
- 'codecommit:GetRepository'
- 'codecommit:GitPush'
- 'codecommit:ListRepositories'
- 'codepipeline:CreatePipeline'
- 'codepipeline:DeletePipeline'
- 'codepipeline:GetPipeline'
- 'codepipeline:GetPipelineState'
- 'codepipeline:StartPipelineExecution'
- 'codepipeline:UpdatePipeline'
- 'iam:CreateRole'
- 'iam:DeleteRole'
- 'iam:DeleteRolePolicy'
- 'iam:GetRole'
- 'iam:GetRolePolicy'
- 'iam:PassRole'
- 'iam:PutRolePolicy'
- 's3:CreateBucket'
- 's3:DeleteBucket'
- 's3:DeleteBucketPolicy'
- 's3:DeleteObject'
- 's3:GetBucketLocation'
- 's3:GetBucketPolicy'
- 's3:ListAllMyBuckets'
- 's3:ListBucket'
- 's3:PutAccelerateConfiguration'
- 's3:PutAccountPublicAccessBlock'
- 's3:PutBucketAcl'
- 's3:PutBucketPolicy'
- 's3:PutBucketPublicAccessBlock'
- 's3:PutBucketVersioning'
- 's3:PutEncryptionConfiguration'
- 's3:PutLifecycleConfiguration'
Effect: Allow
Resource: ['*']
RoleName: !Sub '${PipelineName}-CfnDeploy'
CodePipelineRole:
DependsOn:
- CloudFormationDeployActionRole
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: codepipeline-service
PolicyDocument:
Statement:
- Action:
- 'cloudformation:CreateStack'
- 'cloudformation:DeleteStack'
- 'cloudformation:DescribeStackEvents'
- 'cloudformation:DescribeStackResource'
- 'cloudformation:DescribeStackResources'
- 'cloudformation:DescribeStacks'
- 'cloudformation:GetTemplate'
- 'cloudformation:UpdateStack'
- 'codebuild:BatchGetBuilds'
- 'codebuild:StartBuild'
- 'codecommit:CancelUploadArchive'
- 'codecommit:GetBranch'
- 'codecommit:GetCommit'
- 'codecommit:GetUploadArchiveStatus'
- 'codecommit:UploadArchive'
- 'iam:PassRole'
- 's3:CreateBucket'
- 's3:DeleteBucket'
- 's3:DeleteBucketEncryption'
- 's3:DeleteBucketPolicy'
- 's3:DeleteObject'
- 's3:DescribeBucketPolicy'
- 's3:GetBucketEncryption'
- 's3:GetBucketPolicy'
- 's3:GetBucketPolicyStatus'
- 's3:GetBucketVersioning'
- 's3:GetEncryptionConfiguration'
- 's3:GetObject'
- 's3:GetObjectVersion'
- 's3:ListBucket'
- 's3:PutBucketPolicy'
- 's3:PutEncryptionConfiguration'
- 's3:PutObject'
- 's3:SetBucketEncryption'
Resource: ['*']
Effect: Allow
Version: 2012-10-17
RoleName: !Sub '${PipelineName}-Pipeline'
CodePipeline:
Type: 'AWS::CodePipeline::Pipeline'
Properties:
ArtifactStore:
Type: S3
Location: !Ref CodePipelineBucket
Name: !Ref PipelineName
RestartExecutionOnUpdate: true
RoleArn: !GetAtt CodePipelineRole.Arn
Stages:
- Name: Source
Actions:
- InputArtifacts: []
Name: Source
ActionTypeId:
Category: Source
Owner: AWS
Version: '1'
Provider: CodeCommit
OutputArtifacts:
- Name: 'CodeCommitSource'
Configuration:
BranchName: 'master'
RepositoryName: !GetAtt CodeCommitRepository.Name
RunOrder: 1
- Name: AdministerPipeline
Actions:
- Name: 'AdministerPipeline'
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: '1'
Configuration:
ActionMode: REPLACE_ON_FAILURE
Capabilities: CAPABILITY_NAMED_IAM
RoleArn: !GetAtt CloudFormationDeployActionRole.Arn
StackName: !Sub '${PipelineName}-Inception'
TemplateConfiguration: 'CodeCommitSource::aws_seed.json'
TemplatePath: 'CodeCommitSource::aws_seed.yml'
InputArtifacts:
- Name: 'CodeCommitSource'
RunOrder: 1
- Name: Deploy
Actions:
- Name: DeployApplication
ActionTypeId:
Category: Build
Owner: AWS
Version: '1'
Provider: CodeBuild
Configuration:
ProjectName: !Ref CodeBuildProject
InputArtifacts:
- Name: 'CodeCommitSource'
OutputArtifacts:
- Name: 'Ignored'
RunOrder: 2
CodeBuildRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: [codebuild.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
Policies:
- PolicyName: codebuild-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 'dynamodb:CreateTable'
- 'dynamodb:DeleteTable'
- 'dynamodb:DescribeTable'
- 'dynamodb:ListTables'
- 'dynamodb:ListTagsOfResource'
- 'dynamodb:TagResource'
- 'dynamodb:UntagResource'
- 'dynamodb:UpdateTable'
- 'dynamodb:UpdateTimeToLive'
- 'apigateway:DELETE'
- 'apigateway:GET'
- 'apigateway:PATCH'
- 'apigateway:POST'
- 'apigateway:PUT'
- 'cloudformation:CreateStack'
- 'cloudformation:DeleteStack'
- 'cloudformation:DescribeStackEvents'
- 'cloudformation:DescribeStackResource'
- 'cloudformation:DescribeStackResources'
- 'cloudformation:DescribeStacks'
- 'cloudformation:ListStackResources'
- 'cloudformation:UpdateStack'
- 'cloudformation:ValidateTemplate'
- 'iam:CreateRole'
- 'iam:DeleteRole'
- 'iam:DeleteRolePolicy'
- 'iam:GetRole'
- 'iam:GetRolePolicy'
- 'iam:PassRole'
- 'iam:PutRolePolicy'
- 'iam:CreateServiceLinkedRole'
- 'lambda:AddPermission'
- 'lambda:CreateFunction'
- 'lambda:DeleteFunction'
- 'lambda:GetFunction'
- 'lambda:GetFunctionConfiguration'
- 'lambda:ListVersionsByFunction'
- 'lambda:PublishVersion'
- 'lambda:RemovePermission'
- 'lambda:UpdateFunctionCode'
- 'lambda:UpdateFunctionConfiguration'
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:DeleteLogGroup'
- 'logs:DeleteLogStream'
- 'logs:DescribeLogGroups'
- 'logs:PutLogEvents'
- 's3:CreateBucket'
- 's3:DeleteBucket'
- 's3:DeleteBucketPolicy'
- 's3:DeleteObject'
- 's3:Get*'
- 's3:GetEncryptionConfiguration'
- 's3:ListBucket'
- 's3:PutBucketPolicy'
- 's3:PutBucketWebsite'
- 's3:PutEncryptionConfiguration'
- 's3:PutObject'
- 's3:PutObjectAcl'
- 's3:PutObjectVersionAcl'
- 's3:SetBucketEncryption'
- 's3:PutBucketWebsite'
Resource: '*'
Version: 2012-10-17
RoleName: !Sub '${PipelineName}-CodeBuild'
CodeBuildProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Artifacts:
Packaging: ZIP
Type: CODEPIPELINE
Description: Deploy Application
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:2.0
PrivilegedMode: true
Name: !Ref PipelineName
ServiceRole: !GetAtt CodeBuildRole.Arn
Source:
BuildSpec: 'app/buildspec.yml'
Type: CODEPIPELINE
TimeoutInMinutes: 10
Outputs:
CodeCommitRepositoryArn:
Description: CodeCommit Arn
Value: !GetAtt CodeCommitRepository.Arn
CodeCommitRepositoryCloneUrlHttp:
Description: CodeCommit CloneUrlHttp
Value: !GetAtt CodeCommitRepository.CloneUrlHttp
CloudFormationDeployActionRoleArn:
Description: CloudFormationDeployActionRole Arn
Value: !GetAtt CloudFormationDeployActionRole.Arn
CodePipelineRoleArn:
Description: CodePipelineRole Arn
Value: !GetAtt CodePipelineRole.Arn
CodePipelineName:
Description: CodePipeline Name
Value: !Ref CodePipeline