Skip to content

Commit f607be5

Browse files
authored
Merge pull request #68 from hsohail94/hsohail94/ami-distribution-configuration-settings
feat: Add option to set up Distribution Configuration for cross-account access to images
2 parents e12dbad + 080bb75 commit f607be5

File tree

5 files changed

+200
-119
lines changed

5 files changed

+200
-119
lines changed

API.md

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

104116
export 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
}

test/imagepipeline.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const propsWithVolumeConfig: ImagePipelineProps = {
5555
volumeType: 'gp3',
5656
throughput: 1000,
5757
},
58+
enableCrossAccountDistribution: true,
59+
distributionAccountIDs: ['111222333444', '222444666888'],
60+
distributionRegions: ['us-east-1', 'us-west-2'],
5861
};
5962

6063
beforeAll(() => {
@@ -157,6 +160,10 @@ test('Infrastructure Configuration is built with provided EBS volume properties'
157160
SecurityGroupIds: ['sg-12345678'],
158161
SubnetId: 'subnet-12345678',
159162
});
163+
templateWithVolume.hasResourceProperties('AWS::ImageBuilder::DistributionConfiguration', {
164+
Name: 'TestImageRecipe-distribution-config',
165+
Description: 'Cross account distribution settings for TestImageRecipe',
166+
});
160167
});
161168

162169

0 commit comments

Comments
 (0)