@@ -99,6 +99,18 @@ export interface ImagePipelineProps {
9999 * Store vulnerability scans through AWS Inpsector in ECR using these image tags (if option is enabled)
100100 */
101101 readonly vulnScansRepoTags ?: string [ ] ;
102+ /**
103+ * Set to true if you want to copy this AMI to other accounts using a Distribution Configuration
104+ */
105+ readonly enableCrossAccountDistribution ?: boolean ;
106+ /**
107+ * List of accounts to copy this AMI to, if the option to do so is enabled
108+ */
109+ readonly distributionAccountIDs ?: string [ ] ;
110+ /**
111+ * List of regions to copy this AMI to, if the option to do so is enabled
112+ */
113+ readonly distributionRegions ?: string [ ] ;
102114}
103115
104116export class ImagePipeline extends Construct {
@@ -224,6 +236,29 @@ export class ImagePipeline extends Construct {
224236 } ,
225237 } ;
226238 }
239+ if ( props . enableCrossAccountDistribution ) {
240+ const distributionsList : imagebuilder . CfnDistributionConfiguration . DistributionProperty [ ] = [ ] ;
241+ props . distributionRegions ?. forEach ( distributionRegion => {
242+ const distributionConfig : any = {
243+ region : distributionRegion ,
244+ amiDistributionConfiguration : {
245+ name : `${ props . imageRecipe } -${ distributionRegion } ` ,
246+ description : `copy AMI ${ props . imageRecipe } to ${ distributionRegion } ` ,
247+ targetAccountIds : props . distributionAccountIDs ,
248+ } ,
249+ } ;
250+ distributionsList . push ( distributionConfig ) ;
251+ } ) ;
252+ const amiDistributionConfiguration = new imagebuilder . CfnDistributionConfiguration ( this , 'amiDistributionConfiguration' , {
253+ name : `${ props . imageRecipe } -distribution-config` ,
254+ description : `Cross account distribution settings for ${ props . imageRecipe } ` ,
255+ distributions : distributionsList ,
256+ } ) ;
257+ imagePipelineProps = {
258+ ...imagePipelineProps ,
259+ distributionConfigurationArn : amiDistributionConfiguration . attrArn ,
260+ } ;
261+ }
227262 new imagebuilder . CfnImagePipeline ( this , 'ImagePipeline' , imagePipelineProps ) ;
228263 }
229264}
0 commit comments