Skip to content

Commit 6e7067c

Browse files
authored
Merge pull request #256 from lvthillo/main
feat: Add Name and Schedule props
2 parents 5a19b82 + 82658ba commit 6e7067c

File tree

3 files changed

+161
-1
lines changed

3 files changed

+161
-1
lines changed

API.md

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

src/index.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,24 @@ export interface VolumeProps {
3838
readonly ebs: imagebuilder.CfnImageRecipe.EbsInstanceBlockDeviceSpecificationProperty;
3939
}
4040

41+
export interface ImagePipelineSchedule {
42+
/**
43+
* The cron expression for the schedule.
44+
*/
45+
readonly scheduleExpression: string;
46+
47+
/**
48+
* Optional pipeline execution start condition.
49+
*/
50+
readonly pipelineExecutionStartCondition?: 'EXPRESSION_MATCH_ONLY' | 'EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE';
51+
}
52+
53+
4154
export interface ImagePipelineProps {
55+
/**
56+
* Name of the Image Pipeline
57+
*/
58+
readonly name?: string;
4259
/**
4360
* List of component props
4461
*/
@@ -129,6 +146,10 @@ export interface ImagePipelineProps {
129146
* The tags attached to the resource created by Image Builder
130147
*/
131148
readonly resourceTags?: {[key: string]: string};
149+
/**
150+
* Schedule configuration for the image pipeline.
151+
*/
152+
readonly schedule?: ImagePipelineSchedule;
132153
}
133154

134155
export class ImagePipeline extends Construct {
@@ -254,10 +275,21 @@ export class ImagePipeline extends Construct {
254275
let imagePipelineProps: imagebuilder.CfnImagePipelineProps;
255276
imagePipelineProps = {
256277
infrastructureConfigurationArn: infrastructureConfig.attrArn,
257-
name: `${uid}ImagePipeline`,
278+
name: props.name ? props.name : `${uid}ImagePipeline`,
258279
description: 'A sample image pipeline',
259280
imageRecipeArn: imageRecipe.attrArn,
260281
};
282+
283+
if (props.schedule) {
284+
imagePipelineProps = {
285+
...imagePipelineProps,
286+
schedule: {
287+
scheduleExpression: props.schedule.scheduleExpression,
288+
pipelineExecutionStartCondition: props.schedule.pipelineExecutionStartCondition || 'EXPRESSION_MATCH_ONLY',
289+
},
290+
};
291+
}
292+
261293
if (props.enableVulnScans) {
262294
imagePipelineProps = {
263295
...imagePipelineProps,

test/imagepipeline.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const props: ImagePipelineProps = {
2525
amiIdSsmPath: '/ec2-image-builder/al2-x86',
2626
amiIdSsmAccountId: '11223344556',
2727
amiIdSsmRegion: 'us-east-1',
28+
name: 'TestImagePipeline',
2829
};
2930

3031
const propsWithNetworking: ImagePipelineProps = {
@@ -69,6 +70,21 @@ const propsWithVolumeConfig: ImagePipelineProps = {
6970
distributionRegions: ['us-east-1'],
7071
};
7172

73+
const propsWithSchedule: ImagePipelineProps = {
74+
...props,
75+
schedule: {
76+
scheduleExpression: 'cron(0 0 * * ? *)',
77+
pipelineExecutionStartCondition: 'EXPRESSION_MATCH_ONLY',
78+
},
79+
};
80+
81+
const propsWithDefaultSchedule: ImagePipelineProps = {
82+
...props,
83+
schedule: {
84+
scheduleExpression: 'cron(0 12 * * ? *)',
85+
},
86+
};
87+
7288
beforeAll(() => {
7389
process.env.CDK_DEFAULT_ACCOUNT = '123456789012';
7490
process.env.CDK_DEFAULT_REGION = 'us-east-1';
@@ -83,6 +99,12 @@ beforeAll(() => {
8399
template = Template.fromStack(testStack);
84100
});
85101

102+
test('Image Pipeline is created with custom name', () => {
103+
template.hasResourceProperties('AWS::ImageBuilder::ImagePipeline', {
104+
Name: 'TestImagePipeline',
105+
});
106+
});
107+
86108
test('Infrastructure Configuration SNS topic is created', () => {
87109
template.resourceCountIs('AWS::SNS::Topic', 1);
88110
});
@@ -238,6 +260,43 @@ test('Image Pipeline has Inspector vulnerability scans configured', () => {
238260
});
239261
});
240262

263+
test('Image Pipeline supports schedule configuration', () => {
264+
const app1 = new cdk.App();
265+
const testStack1 = new cdk.Stack(app1, 'testStackWithSchedule', {
266+
env: {
267+
account: process.env.CDK_DEFAULT_ACCOUNT,
268+
region: process.env.CDK_DEFAULT_REGION,
269+
},
270+
});
271+
272+
new ImagePipeline(testStack1, 'ImagePipelineWithSchedule', propsWithSchedule);
273+
const templateWithSchedule = Template.fromStack(testStack1);
274+
275+
templateWithSchedule.hasResourceProperties('AWS::ImageBuilder::ImagePipeline', {
276+
Schedule: {
277+
ScheduleExpression: 'cron(0 0 * * ? *)',
278+
PipelineExecutionStartCondition: 'EXPRESSION_MATCH_ONLY',
279+
},
280+
});
281+
282+
// Test with default execution condition
283+
const app2 = new cdk.App();
284+
const testStack2 = new cdk.Stack(app2, 'testStackWithDefaultSchedule', {
285+
env: {
286+
account: process.env.CDK_DEFAULT_ACCOUNT,
287+
region: process.env.CDK_DEFAULT_REGION,
288+
},
289+
});
290+
291+
new ImagePipeline(testStack2, 'ImagePipelineWithDefaultSchedule', propsWithDefaultSchedule);
292+
const templateWithDefaultSchedule = Template.fromStack(testStack2);
293+
294+
templateWithDefaultSchedule.hasResourceProperties('AWS::ImageBuilder::ImagePipeline', {
295+
Schedule: {
296+
ScheduleExpression: 'cron(0 12 * * ? *)',
297+
},
298+
});
299+
});
241300

242301
test('ImagePipeline exposes components as properties', () => {
243302
const app = new cdk.App();

0 commit comments

Comments
 (0)