Skip to content

Commit c1a7eb3

Browse files
authored
Merge pull request #77 from dannysteenman/main
fix: improve components props
2 parents c73a8cf + 84b0d56 commit c1a7eb3

File tree

4 files changed

+161
-69
lines changed

4 files changed

+161
-69
lines changed

API.md

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

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,18 @@ import { Construct } from 'constructs';
4747
// ...
4848
// Create a new image pipeline with the required properties
4949
new ImagePipeline(this, "MyImagePipeline", {
50-
componentDocuments: ['component_example.yml', 'component_example_2.yml'],
51-
componentNames: ['Component', 'Component2'],
52-
componentVersions: ['0.0.1', '0.1.0'],
50+
components: [
51+
{
52+
document: 'component_example.yml',
53+
name: 'Component',
54+
version: '0.0.1',
55+
},
56+
{
57+
document: 'component_example_2.yml',
58+
name: 'Component2',
59+
version: '0.1.0',
60+
},
61+
],
5362
kmsKeyAlias: 'alias/my-key',
5463
profileName: 'ImagePipelineInstanceProfile',
5564
infraConfigName: 'MyInfrastructureConfiguration',
@@ -96,9 +105,18 @@ const private_subnet = vpc.privateSubnets;
96105
97106
98107
new ImagePipeline(this, "MyImagePipeline", {
99-
componentDocuments: ['component_example.yml', 'component_example_2.yml'],
100-
componentNames: ['Component', 'Component2'],
101-
componentVersions: ['0.0.1', '0.1.0'],
108+
components: [
109+
{
110+
document: 'component_example.yml',
111+
name: 'Component',
112+
version: '0.0.1',
113+
},
114+
{
115+
document: 'component_example_2.yml',
116+
name: 'Component2',
117+
version: '0.1.0',
118+
},
119+
],
102120
kmsKeyAlias: 'alias/my-key',
103121
profileName: 'ImagePipelineInstanceProfile',
104122
infraConfigName: 'MyInfrastructureConfiguration',
@@ -121,9 +139,18 @@ from constructs import Construct
121139
image_pipeline = ImagePipeline(
122140
self,
123141
"LatestImagePipeline",
124-
component_documents=["component_example.yml", "component_example2.yml"],
125-
component_names=["Component", "Component2"],
126-
component_versions=["0.0.1", "0.1.0"],
142+
components=[
143+
{
144+
document: 'component_example.yml',
145+
name: 'Component',
146+
version: '0.0.1',
147+
},
148+
{
149+
document: 'component_example_2.yml',
150+
name: 'Component2',
151+
version: '0.1.0',
152+
},
153+
],
127154
kms_key_alias="alias/my-key",
128155
image_recipe="Recipe4",
129156
pipeline_name="Pipeline4",
@@ -172,9 +199,18 @@ priv_subnets = vpc.private_subnets
172199
image_pipeline = ImagePipeline(
173200
self,
174201
"LatestImagePipeline",
175-
component_documents=["component_example.yml", "component_example2.yml"],
176-
component_names=["Component", "Component2"],
177-
component_versions=["0.0.1", "0.1.0"],
202+
components=[
203+
{
204+
document: 'component_example.yml',
205+
name: 'Component',
206+
version: '0.0.1',
207+
},
208+
{
209+
document: 'component_example_2.yml',
210+
name: 'Component2',
211+
version: '0.1.0',
212+
},
213+
],
178214
kms_key_alias="alias/my-key",
179215
image_recipe="Recipe4",
180216
pipeline_name="Pipeline4",

src/index.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ import {
1111
import { SnsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
1212
import { Construct } from 'constructs';
1313

14-
export interface ImagePipelineProps {
14+
export interface ComponentProps {
1515
/**
16-
* Relative path to Image Builder component documents
16+
* Relative path to Image Builder component document
1717
*/
18-
readonly componentDocuments: string[];
18+
readonly document: string;
1919
/**
20-
* Names of the Component Documents
20+
* Name of the Component Document
2121
*/
22-
readonly componentNames: string[];
22+
readonly name: string;
2323
/**
24-
* Versions for each component document
24+
* Version for each component document
2525
*/
26-
readonly componentVersions: string[];
26+
readonly version: string;
27+
}
28+
29+
export interface ImagePipelineProps {
30+
/**
31+
* List of component props
32+
*/
33+
readonly components: ComponentProps[];
2734
/**
2835
* Name of the instance profile that will be associated with the Instance Configuration.
2936
*/
@@ -130,6 +137,7 @@ export interface ImagePipelineProps {
130137

131138
export class ImagePipeline extends Construct {
132139
imageRecipeComponents: imagebuilder.CfnImageRecipe.ComponentConfigurationProperty[];
140+
133141
constructor(scope: Construct, id: string, props: ImagePipelineProps) {
134142
super(scope, id);
135143
let infrastructureConfig: imagebuilder.CfnInfrastructureConfiguration;
@@ -140,6 +148,7 @@ export class ImagePipeline extends Construct {
140148
const kmsKey = kms.Key.fromLookup(this, 'KmsKeyLookup', {
141149
aliasName: props.kmsKeyAlias,
142150
});
151+
143152
const topic = new sns.Topic(this, 'ImageBuilderTopic', {
144153
displayName: 'Image Builder Notify',
145154
masterKey: kmsKey,
@@ -219,16 +228,16 @@ export class ImagePipeline extends Construct {
219228
}
220229
imageRecipe = new imagebuilder.CfnImageRecipe(this, 'ImageRecipe', imageRecipeProps);
221230

222-
props.componentDocuments.forEach((document, index) => {
223-
let component = new imagebuilder.CfnComponent(this, props.componentNames[index], {
224-
name: props.componentNames[index],
225-
platform: props.platform ?? 'Linux',
226-
version: props.componentVersions[index] ?? '0.0.1',
227-
data: readFileSync(document).toString(),
231+
props.components.forEach((component) => {
232+
let newComponent = new imagebuilder.CfnComponent(this, component.name, {
233+
name: component.name,
234+
platform: 'Linux',
235+
version: component.version,
236+
data: readFileSync(component.document).toString(),
228237
});
229238

230239
// add the component to the Image Recipe
231-
this.imageRecipeComponents.push({ componentArn: component.attrArn });
240+
this.imageRecipeComponents.push({ componentArn: newComponent.attrArn });
232241
imageRecipe.components = this.imageRecipeComponents;
233242
});
234243

@@ -322,4 +331,4 @@ export class ImagePipeline extends Construct {
322331
}
323332
new imagebuilder.CfnImagePipeline(this, 'ImagePipeline', imagePipelineProps);
324333
}
325-
}
334+
}

test/imagepipeline.test.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ import { ImagePipeline, ImagePipelineProps } from '../src';
55
let template: Template;
66

77
const props: ImagePipelineProps = {
8-
componentDocuments: ['test/test_component_example.yml', 'test/test_component_example_2.yml'],
9-
componentNames: ['TestComponent', 'TestComponent2'],
10-
componentVersions: ['1.0.0'],
8+
components: [
9+
{
10+
document: 'test/test_component_example.yml',
11+
name: 'TestComponent',
12+
version: '1.0.0',
13+
},
14+
{
15+
document: 'test/test_component_example_2.yml',
16+
name: 'TestComponent2',
17+
version: '1.0.0',
18+
},
19+
],
1120
profileName: 'TestProfile',
1221
infraConfigName: 'TestInfrastructureConfig',
1322
imageRecipe: 'TestImageRecipe',
@@ -24,9 +33,13 @@ const props: ImagePipelineProps = {
2433
};
2534

2635
const propsWithNetworking: ImagePipelineProps = {
27-
componentDocuments: ['test/test_component_example.yml'],
28-
componentNames: ['TestComponent'],
29-
componentVersions: ['1.0.0'],
36+
components: [
37+
{
38+
document: 'test/test_component_example.yml',
39+
name: 'TestComponent',
40+
version: '1.0.0',
41+
},
42+
],
3043
profileName: 'TestProfile',
3144
infraConfigName: 'TestInfrastructureConfig',
3245
imageRecipe: 'TestImageRecipe',
@@ -38,9 +51,13 @@ const propsWithNetworking: ImagePipelineProps = {
3851
};
3952

4053
const propsWithVolumeConfig: ImagePipelineProps = {
41-
componentDocuments: ['test/test_component_example.yml'],
42-
componentNames: ['TestComponent'],
43-
componentVersions: ['1.0.0'],
54+
components: [
55+
{
56+
document: 'test/test_component_example.yml',
57+
name: 'TestComponent',
58+
version: '1.0.0',
59+
},
60+
],
4461
profileName: 'TestProfile',
4562
infraConfigName: 'TestInfrastructureConfig',
4663
imageRecipe: 'TestImageRecipe',
@@ -200,7 +217,7 @@ test.skip('Infrastructure Configuration DependsOn Instance Profile', () => {
200217
});
201218

202219
test('Image Builder Component is created', () => {
203-
template.resourceCountIs('AWS::ImageBuilder::Component', props.componentDocuments.length);
220+
template.resourceCountIs('AWS::ImageBuilder::Component', props.components.length);
204221
});
205222

206223
test('Image Recipe is created', () => {
@@ -220,4 +237,4 @@ test('Image Pipeline has Inspector vulnerability scans configured', () => {
220237
},
221238
},
222239
});
223-
});
240+
});

0 commit comments

Comments
 (0)