1
- import { expect , haveResource , haveResourceLike , not , SynthUtils } from '@aws-cdk/assert' ;
1
+ import { countResources , expect , haveResource , haveResourceLike , not , SynthUtils } from '@aws-cdk/assert' ;
2
2
import codebuild = require( '@aws-cdk/aws-codebuild' ) ;
3
3
import codecommit = require( '@aws-cdk/aws-codecommit' ) ;
4
4
import codepipeline = require( '@aws-cdk/aws-codepipeline' ) ;
@@ -567,19 +567,19 @@ export = {
567
567
account : pipelineAccount ,
568
568
} ,
569
569
} ) ;
570
- const bucket = new s3 . Bucket ( stack , 'MyBucket' ) ;
571
570
const pipeline = new codepipeline . Pipeline ( stack , 'MyPipeline' , {
572
571
crossRegionReplicationBuckets : {
573
- 'us-west-1' : ' sfo-replication-bucket',
572
+ 'us-west-1' : s3 . Bucket . fromBucketName ( stack , 'ImportedBucket' , ' sfo-replication-bucket') ,
574
573
} ,
575
574
} ) ;
576
575
576
+ const sourceBucket = new s3 . Bucket ( stack , 'MyBucket' ) ;
577
577
const sourceOutput = new codepipeline . Artifact ( 'SourceOutput' ) ;
578
578
const sourceAction = new cpactions . S3SourceAction ( {
579
579
actionName : 'BucketSource' ,
580
580
bucketKey : '/some/key' ,
581
581
output : sourceOutput ,
582
- bucket,
582
+ bucket : sourceBucket ,
583
583
} ) ;
584
584
pipeline . addStage ( {
585
585
stageName : 'Stage1' ,
@@ -619,19 +619,25 @@ export = {
619
619
"Region" : "us-east-1" ,
620
620
"ArtifactStore" : {
621
621
"Type" : "S3" ,
622
+ "Location" : "cdk-cross-region-codepipeline-replication-bucket-685c6feea5fb" ,
622
623
} ,
623
624
} ,
624
625
{
625
626
"Region" : "us-west-1" ,
626
627
"ArtifactStore" : {
627
- "Location" : "sfo-replication-bucket" ,
628
628
"Type" : "S3" ,
629
+ "Location" : "sfo-replication-bucket" ,
629
630
} ,
630
631
} ,
631
632
{
632
633
"Region" : "us-west-2" ,
633
634
"ArtifactStore" : {
634
635
"Type" : "S3" ,
636
+ "EncryptionKey" : {
637
+ "Type" : "KMS" ,
638
+ "Id" : {
639
+ } ,
640
+ } ,
635
641
} ,
636
642
} ,
637
643
] ,
@@ -656,18 +662,90 @@ export = {
656
662
} ,
657
663
] ,
658
664
} ,
659
- ]
665
+ ] ,
660
666
} ) ) ;
661
667
662
- test . equal ( pipeline . crossRegionScaffolding [ pipelineRegion ] , undefined ) ;
663
- test . equal ( pipeline . crossRegionScaffolding [ 'us-west-1' ] , undefined ) ;
668
+ test . equal ( pipeline . crossRegionSupport [ pipelineRegion ] , undefined ) ;
669
+ test . equal ( pipeline . crossRegionSupport [ 'us-west-1' ] , undefined ) ;
670
+
671
+ const usEast1Support = pipeline . crossRegionSupport [ 'us-east-1' ] ;
672
+ test . notEqual ( usEast1Support , undefined ) ;
673
+ test . equal ( usEast1Support . stack . region , 'us-east-1' ) ;
674
+ test . equal ( usEast1Support . stack . account , pipelineAccount ) ;
675
+ test . ok ( usEast1Support . stack . node . id . indexOf ( 'us-east-1' ) !== - 1 ,
676
+ `expected '${ usEast1Support . stack . node . id } ' to contain 'us-east-1'` ) ;
677
+
678
+ test . done ( ) ;
679
+ } ,
680
+
681
+ 'allows specifying only one of artifactBucket and crossRegionReplicationBuckets' ( test : Test ) {
682
+ const stack = new Stack ( ) ;
683
+
684
+ test . throws ( ( ) => {
685
+ new codepipeline . Pipeline ( stack , 'Pipeline' , {
686
+ artifactBucket : new s3 . Bucket ( stack , 'Bucket' ) ,
687
+ crossRegionReplicationBuckets : {
688
+ // even an empty map should trigger this validation...
689
+ } ,
690
+ } ) ;
691
+ } , / O n l y o n e o f a r t i f a c t B u c k e t a n d c r o s s R e g i o n R e p l i c a t i o n B u c k e t s c a n b e s p e c i f i e d ! / ) ;
692
+ test . done ( ) ;
693
+ } ,
694
+
695
+ 'does not create a new artifact Bucket if one was provided in the cross-region Buckets for the Pipeline region' ( test : Test ) {
696
+ const pipelineRegion = 'us-west-2' ;
697
+
698
+ const stack = new Stack ( undefined , undefined , {
699
+ env : {
700
+ region : pipelineRegion ,
701
+ } ,
702
+ } ) ;
703
+ const sourceOutput = new codepipeline . Artifact ( ) ;
704
+ new codepipeline . Pipeline ( stack , 'Pipeline' , {
705
+ crossRegionReplicationBuckets : {
706
+ [ pipelineRegion ] : new s3 . Bucket ( stack , 'Bucket' , {
707
+ bucketName : PhysicalName . of ( 'my-pipeline-bucket' ) ,
708
+ } )
709
+ } ,
710
+ stages : [
711
+ {
712
+ stageName : 'Source' ,
713
+ actions : [
714
+ new cpactions . CodeCommitSourceAction ( {
715
+ actionName : 'Source' ,
716
+ output : sourceOutput ,
717
+ repository : new codecommit . Repository ( stack , 'Repo' , { repositoryName : 'Repo' } ) ,
718
+ } ) ,
719
+ ] ,
720
+ } ,
721
+ {
722
+ stageName : 'Build' ,
723
+ actions : [
724
+ new cpactions . CodeBuildAction ( {
725
+ actionName : 'Build' ,
726
+ input : sourceOutput ,
727
+ project : new codebuild . PipelineProject ( stack , 'Project' ) ,
728
+ } ) ,
729
+ ] ,
730
+ } ,
731
+ ] ,
732
+ } ) ;
733
+
734
+ expect ( stack ) . to ( countResources ( 'AWS::S3::Bucket' , 1 ) ) ;
664
735
665
- const usEast1ScaffoldStack = pipeline . crossRegionScaffolding [ 'us-east-1' ] ;
666
- test . notEqual ( usEast1ScaffoldStack , undefined ) ;
667
- test . equal ( usEast1ScaffoldStack . region , 'us-east-1' ) ;
668
- test . equal ( usEast1ScaffoldStack . account , pipelineAccount ) ;
669
- test . ok ( usEast1ScaffoldStack . node . id . indexOf ( 'us-east-1' ) !== - 1 ,
670
- `expected '${ usEast1ScaffoldStack . node . id } ' to contain 'us-east-1'` ) ;
736
+ expect ( stack ) . to ( haveResourceLike ( 'AWS::CodePipeline::Pipeline' , {
737
+ "ArtifactStores" : [
738
+ {
739
+ "Region" : pipelineRegion ,
740
+ "ArtifactStore" : {
741
+ "Type" : "S3" ,
742
+ "Location" : {
743
+ "Ref" : "Bucket83908E77" ,
744
+ } ,
745
+ } ,
746
+ } ,
747
+ ] ,
748
+ } ) ) ;
671
749
672
750
test . done ( ) ;
673
751
} ,
0 commit comments