-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
835 lines (792 loc) · 25.7 KB
/
template.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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: "AWS CodePipeline shared resources."
Parameters:
GitProviderType:
Type: String
Default: "GitHub"
BuildAccount:
Type: String
Default: ""
DeployAccounts:
Type: CommaDelimitedList
Default: ""
ArtifactsBucketArn:
Type: String
Default: ""
ArtifactsBucketKmsKeyArn:
Type: String
Default: ""
ImageRepositoryArn:
Type: String
Default: ""
BuildPipeline:
Type: String
AllowedValues: ["true", "false"]
Default: "true"
DevPipelineExecutionRole:
Type: String
Default: ""
DevCodeBuildServiceRole:
Type: String
Default: ""
DevCfnExecutionRole:
Type: String
Default: ""
ProdPipelineExecutionRole:
Type: String
Default: ""
ProdCodeBuildServiceRole:
Type: String
Default: ""
ProdCfnExecutionRole:
Type: String
Default: ""
Conditions:
HasDevPipelineExecutionRole: !Not [!Equals [!Ref DevPipelineExecutionRole, ""]]
HasDevCodeBuildServiceRole: !Not [!Equals [!Ref DevCodeBuildServiceRole, ""]]
HasDevCfnExecutionRole: !Not [!Equals [!Ref DevCfnExecutionRole, ""]]
HasProdPipelineExecutionRole: !Not [!Equals [!Ref ProdPipelineExecutionRole, ""]]
HasProdCodeBuildServiceRole: !Not [!Equals [!Ref ProdCodeBuildServiceRole, ""]]
HasProdCfnExecutionRole: !Not [!Equals [!Ref ProdCfnExecutionRole, ""]]
MissingDeployAccounts: !Equals [!Select [0, !Ref DeployAccounts], ""]
IsBuildPipeline: !Equals [!Ref BuildPipeline, "true"]
Resources:
PipelineUser:
Type: AWS::IAM::User
Condition: IsBuildPipeline
Properties:
Policies:
- PolicyName: AssumeRoles
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "sts:AssumeRole"
Resource: "*"
Condition:
StringEquals:
aws:ResourceTag/Role: codepipeline-execution-role
PipelineUserAccessKey:
Type: AWS::IAM::AccessKey
Condition: IsBuildPipeline
Properties:
Serial: 1
Status: Active
UserName: !Ref PipelineUser
PipelineUserSecretKey:
Type: AWS::SecretsManager::Secret
Condition: IsBuildPipeline
Properties:
SecretString: !Sub '{"aws_access_key_id": "${PipelineUserAccessKey}", "aws_secret_access_key": "${PipelineUserAccessKey.SecretAccessKey}"}'
CloudFormationExecutionRole:
Type: AWS::IAM::Role
Properties:
Tags:
- Key: Role
Value: cloudformation-execution-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: cloudformation.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: GrantCloudFormationFullAccess
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: '*'
Resource: '*'
CloudFormationExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Properties:
Name: !Sub "/${AWS::StackName}/BuildCfnExecutionRoleArn"
Type: "String"
Description: "CloudFormation Execution IAM Role ARN"
Value: !GetAtt CloudFormationExecutionRole.Arn
PipelineExecutionRole:
Type: AWS::IAM::Role
Properties:
Tags:
- Key: Role
Value: codepipeline-execution-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
# FIXME: Need to prevent deploy account roles from assuming build account role
- Action:
- "sts:AssumeRole"
Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
- Fn::If:
- IsBuildPipeline
- Effect: Allow
Principal:
AWS: !GetAtt PipelineUser.Arn
Action:
- 'sts:AssumeRole'
- !Ref AWS::NoValue
- Effect: Allow
Principal:
AWS:
Fn::If:
- IsBuildPipeline
- !Ref AWS::AccountId
- !Ref BuildAccount
Action:
- 'sts:AssumeRole'
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- codebuild-service-role
Policies:
# FIXME: What is this permission allowing? Is this maybe only needed
# in the build account?
- PolicyName: AssumePipelineRoles
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- sts:AssumeRole
Resource: "*"
Condition:
StringLike:
aws:ResourceTag/Role:
- codepipeline-execution-role
- codebuild-service-role
- PolicyName: PassCfnRoleToServices
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: 'iam:PassRole'
Resource: !GetAtt CloudFormationExecutionRole.Arn
- PolicyName: CodeBuild
PolicyDocument:
Version: "2012-10-17"
Statement:
# FIXME: Deploy accounts shouldn't need this.
- Effect: Allow
Action:
- "codebuild:StartBuild"
- "codebuild:BatchGetBuilds"
Resource: "*"
- PolicyName: CloudFormationService
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "cloudformation:CreateChangeSet"
- "cloudformation:DeleteChangeSet"
- "cloudformation:DescribeChangeSet"
- "cloudformation:ExecuteChangeSet"
- "cloudformation:DescribeStackEvents"
- "cloudformation:DescribeStacks"
- "cloudformation:GetTemplateSummary"
- "cloudformation:DescribeStackResource"
Resource: '*'
- PolicyName: ArtifactBucketAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- 's3:GetObject*'
- 's3:PutObject*'
- 's3:GetBucket*'
- 's3:List*'
Resource:
Fn::If:
- IsBuildPipeline
- - !Join [ '',[ !GetAtt ArtifactsBucket.Arn, '/*' ] ]
- !GetAtt ArtifactsBucket.Arn
- - !Join [ '',[ !Ref ArtifactsBucketArn, '/*' ] ]
- !Ref ArtifactsBucketArn
- PolicyName: EcrFetch
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
Resource:
Fn::If:
- IsBuildPipeline
- !GetAtt ImageRepository.Arn
- !Ref ImageRepositoryArn
- PolicyName: KmsKeyAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- kms:DescribeKey
- kms:GenerateDataKey*
- kms:Encrypt
- kms:ReEncrypt*
- kms:Decrypt
Resource:
Fn::If:
- IsBuildPipeline
- !GetAtt ArtifactsBucketKmsKey.Arn
- !Ref ArtifactsBucketKmsKeyArn
- Fn::If:
- IsBuildPipeline
- PolicyName: EcrAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "ecr:GetAuthorizationToken"
- "ecr:PutImage"
- "ecr:InitiateLayerUpload"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
Resource: "*"
- !Ref AWS::NoValue
- Fn::If:
- IsBuildPipeline
- PolicyName: CodeStar
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "codestar-connections:UseConnection"
Resource: !Ref CodeStarConnection
- !Ref AWS::NoValue
PipelineExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Properties:
Name: !Sub "/${AWS::StackName}/BuildPipelineExecutionRoleArn"
Type: "String"
Description: "Shared build pipelineeExecution IAM Role ARN"
Value: !GetAtt PipelineExecutionRole.Arn
DevPipelineExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasDevPipelineExecutionRole
Properties:
Name: !Sub "/${AWS::StackName}/DevPipelineExecutionRoleArn"
Type: "String"
Description: "Dev deploy pipeline role"
Value: !Ref DevPipelineExecutionRole
DevCodeBuildServiceRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasDevCodeBuildServiceRole
Properties:
Name: !Sub "/${AWS::StackName}/DevCodeBuildServiceRoleArn"
Type: "String"
Description: "Dev CodeBuild service role"
Value: !Ref DevCodeBuildServiceRole
DevCfnExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasDevCfnExecutionRole
Properties:
Name: !Sub "/${AWS::StackName}/DevCfnExecutionRoleArn"
Type: "String"
Description: "Dev deploy CFN role"
Value: !Ref DevCfnExecutionRole
ProdPipelineExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasProdPipelineExecutionRole
Properties:
Name: !Sub "/${AWS::StackName}/ProdPipelineExecutionRoleArn"
Type: "String"
Description: "Prod deploy pipeline role"
Value: !Ref ProdPipelineExecutionRole
ProdCodeBuildServiceRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasProdCodeBuildServiceRole
Properties:
Name: !Sub "/${AWS::StackName}/ProdCodeBuildServiceRoleArn"
Type: "String"
Description: "Prod CodeBuild service role"
Value: !Ref ProdCodeBuildServiceRole
ProdCfnExecutionRoleArnSsmParam:
Type: AWS::SSM::Parameter
Condition: HasProdCfnExecutionRole
Properties:
Name: !Sub "/${AWS::StackName}/ProdCfnExecutionRoleArn"
Type: "String"
Description: "Prod deploy CFN role"
Value: !Ref ProdCfnExecutionRole
ArtifactsBucketKmsKey:
Type: AWS::KMS::Key
Condition: IsBuildPipeline
Properties:
Description: Artifact Bucket KMS key
MultiRegion: true
KeyPolicy:
Version: '2012-10-17'
Id: ArtifactBucket
Statement:
- Sid: Allow access for principals from this account
Effect: Allow
Principal:
AWS: !Ref AWS::AccountId
Action: kms:*
Resource: '*'
- Sid: Allow codepipeline
Effect: Allow
Principal:
Service: 'codepipeline.amazonaws.com'
Action:
- kms:DescribeKey
- kms:GenerateDataKey*
- kms:Encrypt
- kms:ReEncrypt*
- kms:Decrypt
Resource: '*'
- Sid: Allow access through S3 for all deployment account pipeline roles
Effect: Allow
Principal:
AWS: !Ref DeployAccounts
Action:
- kms:DescribeKey
- kms:GenerateDataKey*
- kms:Encrypt
- kms:ReEncrypt*
- kms:Decrypt
Resource: '*'
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- codebuild-service-role
- cloudformation-execution-role
ArtifactsBucketKmsKeySsmParam:
Type: AWS::SSM::Parameter
Condition: IsBuildPipeline
Properties:
Name: !Sub "/${AWS::StackName}/ArtifactsBucketKmsKey"
Type: "String"
Description: "KMS key for artifacts"
Value: !GetAtt ArtifactsBucketKmsKey.Arn
ArtifactsBucket:
Type: AWS::S3::Bucket
Condition: IsBuildPipeline
DeletionPolicy: "Retain"
UpdateReplacePolicy: "Retain"
Properties:
LoggingConfiguration:
DestinationBucketName:
!Ref ArtifactsLoggingBucket
LogFilePrefix: "artifacts-logs"
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
ArtifactsBucketSsmParameter:
Type: AWS::SSM::Parameter
Condition: IsBuildPipeline
Properties:
Name: !Sub "/${AWS::StackName}/ArtifactsBucket"
Type: "String"
Description: "Artifacts bucket name"
Value: !Ref ArtifactsBucket
ArtifactsBucketPolicy:
Type: AWS::S3::BucketPolicy
Condition: IsBuildPipeline
Properties:
Bucket: !Ref ArtifactsBucket
PolicyDocument:
Statement:
- Effect: "Deny"
Action: "s3:*"
Principal: "*"
Resource:
- !Join [ '',[ !GetAtt ArtifactsBucket.Arn, '/*' ] ]
- !GetAtt ArtifactsBucket.Arn
Condition:
Bool:
aws:SecureTransport: false
- Effect: "Allow"
Action:
- 's3:GetObject*'
- 's3:PutObject*'
- 's3:GetBucket*'
- 's3:List*'
Resource:
- !Join ['',[!GetAtt ArtifactsBucket.Arn, '/*']]
- !GetAtt ArtifactsBucket.Arn
Principal:
AWS:
- !GetAtt PipelineExecutionRole.Arn
- !GetAtt CloudFormationExecutionRole.Arn
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- cloudformation-execution-role
- Fn::If:
- MissingDeployAccounts
- !Ref AWS::NoValue
- Effect: "Allow"
Action:
- 's3:GetObject*'
- 's3:PutObject*'
- 's3:GetBucket*'
- 's3:List*'
Resource:
- !Join ['',[!GetAtt ArtifactsBucket.Arn, '/*']]
- !GetAtt ArtifactsBucket.Arn
Principal:
AWS: !Ref DeployAccounts
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- codebuild-service-role
- cloudformation-execution-role
ArtifactsLoggingBucket:
Type: AWS::S3::Bucket
Condition: IsBuildPipeline
DeletionPolicy: "Retain"
UpdateReplacePolicy: "Retain"
Properties:
AccessControl: "LogDeliveryWrite"
VersioningConfiguration:
Status: Enabled
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
ArtifactsLoggingBucketPolicy:
Type: AWS::S3::BucketPolicy
Condition: IsBuildPipeline
Properties:
Bucket: !Ref ArtifactsLoggingBucket
PolicyDocument:
Statement:
- Effect: "Deny"
Action: "s3:*"
Principal: "*"
Resource:
- !Join [ '',[ !GetAtt ArtifactsLoggingBucket.Arn, '/*' ] ]
- !GetAtt ArtifactsLoggingBucket.Arn
Condition:
Bool:
aws:SecureTransport: false
CodeBuildServicePolicy:
Type: AWS::IAM::ManagedPolicy
Condition: IsBuildPipeline
Properties:
Description: "Managed policy for CodeBuild service roles"
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: AssumeCrossAccountCodeBuildRoles
Effect: Allow
Action:
- "sts:AssumeRole"
Resource: "*"
Condition:
StringLike:
aws:ResourceTag/Role:
- codepipeline-execution-role
- codebuild-service-role
- Sid: CodeBuildLogs
Effect: Allow
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*"
- Sid: ArtifactBucketAccess
Effect: Allow
Action:
- "s3:GetObject"
- "s3:GetObjectVersion"
- "s3:PutObject"
Resource:
- !Join ['',[!GetAtt ArtifactsBucket.Arn, '/*']]
- Sid: ListPoliciesForSamCli
Effect: Allow
Action:
- "iam:ListPolicies"
Resource:
- "*"
- Sid: PipelineKmsKeyAccess
Effect: Allow
Action:
- kms:DescribeKey
- kms:GenerateDataKey*
- kms:Encrypt
- kms:ReEncrypt*
- kms:Decrypt
Resource: !GetAtt ArtifactsBucketKmsKey.Arn
CodeBuildServicePolicyArnSsmParameter:
Type: AWS::SSM::Parameter
Condition: IsBuildPipeline
Properties:
Name: !Sub "/${AWS::StackName}/CodeBuildServicePolicyArn"
Type: "String"
Description: "CodeBuild service managed policy ARN"
Value: !Ref CodeBuildServicePolicy
CodeBuildServiceRole:
Type: AWS::IAM::Role
Properties:
Tags:
- Key: Role
Value: codebuild-service-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
# FIXME: Need to prevent deploy account roles from assuming build account role
- Action:
- "sts:AssumeRole"
Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
- Effect: Allow
Principal:
AWS:
Fn::If:
- IsBuildPipeline
- !Ref AWS::AccountId
- !Ref BuildAccount
Action:
- 'sts:AssumeRole'
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- codebuild-service-role
ManagedPolicyArns:
- !If
- IsBuildPipeline
- !Ref CodeBuildServicePolicy
- !Ref AWS::NoValue
Policies:
Fn::If:
- IsBuildPipeline
- !Ref AWS::NoValue
- - PolicyName: CloudFormation
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "cloudformation:describe*"
Resource: "*"
- PolicyName: CloudTrail
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "cloudtrail:*"
Resource: "*"
- PolicyName: CloudWatch
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "cloudwatch:*"
Resource: "*"
- PolicyName: CloudWatchLogs
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "logs:*"
Resource: "*"
- PolicyName: DDB
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "dynamodb:*"
Resource: "*"
- PolicyName: EventBridge
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "events:*"
Resource: "*"
- PolicyName: Lambda
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "lambda:*"
Resource: "*"
- PolicyName: S3
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "s3:*"
Resource: "*"
- PolicyName: SNS
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "sns:*"
Resource: "*"
- PolicyName: SQS
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "sqs:*"
Resource: "*"
- PolicyName: SSM
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "ssm:*"
Resource: "*"
- PolicyName: StepFunctions
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "states:*"
Resource: "*"
- PolicyName: XRay
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "xray:*"
Resource: "*"
CodeBuildServiceRoleArnSsmParameter:
Type: AWS::SSM::Parameter
Properties:
Name: !Sub "/${AWS::StackName}/CodeBuildServiceRoleArn"
Type: "String"
Description: "CodeBuild service role ARN"
Value: !Ref CodeBuildServiceRole
CodeStarConnection:
Type: AWS::CodeStarConnections::Connection
Condition: IsBuildPipeline
Properties:
ConnectionName: GitRepositoryConnection
ProviderType: !Ref GitProviderType
CodeStarConnectionArnSsmParam:
Type: AWS::SSM::Parameter
Condition: IsBuildPipeline
Properties:
Type: String
Description: "ARN of CodeStar connection"
Name: !Sub "/${AWS::StackName}/CodeStarConnectionArn"
Value: !Ref CodeStarConnection
ImageRepository:
Type: AWS::ECR::Repository
Condition: IsBuildPipeline
Properties:
RepositoryPolicyText:
Version: "2012-10-17"
Statement:
- Sid: LambdaECRImageRetrievalPolicy
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:GetRepositoryPolicy"
- "ecr:SetRepositoryPolicy"
- "ecr:DeleteRepositoryPolicy"
- Sid: AllowPushPull
Effect: Allow
Principal:
AWS: !Ref AWS::AccountId
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
- "ecr:PutImage"
- "ecr:InitiateLayerUpload"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- cloudformation-execution-role
- Sid: AllowPushPullCrossAccount
Effect: Allow
Principal:
AWS: !Ref DeployAccounts
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
- "ecr:PutImage"
- "ecr:InitiateLayerUpload"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
Condition:
StringLike:
aws:PrincipalTag/Role:
- codepipeline-execution-role
- codebuild-service-role
- cloudformation-execution-role
ImageRepositoryArnSsmParam:
Type: AWS::SSM::Parameter
Condition: IsBuildPipeline
Properties:
Type: String
Description: "ARN of ECR repo"
Name: !Sub "/${AWS::StackName}/ImageRepositoryArn"
Value: !GetAtt ImageRepository.Arn
Outputs:
PipelineUser:
Description: ARN of the Pipeline IAM User
Condition: IsBuildPipeline
Value: !GetAtt PipelineUser.Arn
PipelineUserSecretKey:
Description: AWS Access Key and Secret Key of pipeline user.
Condition: IsBuildPipeline
Value: !Ref PipelineUserSecretKey
CloudFormationExecutionRole:
Description: ARN of the IAM Role (CloudFormationExecutionRole)
Value: !GetAtt CloudFormationExecutionRole.Arn
PipelineExecutionRole:
Description: ARN of the IAM Role (PipelineExecutionRole)
Value: !GetAtt PipelineExecutionRole.Arn
CodeBuildServiceRole:
Description: "ARN of the IAM Role (CodeBuildServiceRole)"
Value: !GetAtt CodeBuildServiceRole.Arn
ArtifactsBucket:
Description: ARN of the Artifacts bucket
Value:
Fn::If:
- IsBuildPipeline
- !GetAtt ArtifactsBucket.Arn
- !Ref ArtifactsBucketArn
ArtifactsBucketKmsKey:
Description: ARN of the Artifacts bucket KMS key
Value:
Fn::If:
- IsBuildPipeline
- !GetAtt ArtifactsBucketKmsKey.Arn
- !Ref ArtifactsBucketKmsKeyArn
ImageRepository:
Description: ARN of the ECR image repository
Condition: IsBuildPipeline
Value:
Fn::If:
- IsBuildPipeline
- !GetAtt ImageRepository.Arn
- !Ref ImageRepositoryArn