Skip to content

Commit 3a1e0e6

Browse files
authored
Merge pull request #158 from hanseartic/feature/expose_components
feat: expose components as properties
2 parents 925f342 + be93118 commit 3a1e0e6

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

API.md

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ from aws_cdk import (
165165
Stack,
166166
aws_ec2 as ec2,
167167
)
168-
from consturcts import Construct
168+
from constructs import Construct
169169
from cdk_image_pipeline import ImagePipeline
170170
171171
# ...

src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ export interface ImagePipelineProps {
129129

130130
export class ImagePipeline extends Construct {
131131
imageRecipeComponents: imagebuilder.CfnImageRecipe.ComponentConfigurationProperty[];
132+
/**
133+
* The internal image pipeline created by this construct.
134+
*/
135+
readonly pipeline: imagebuilder.CfnImagePipeline;
136+
/**
137+
* SNS Topic where the internal ImageBuilder will notify about new builds.
138+
*/
139+
readonly builderSnsTopic: sns.Topic;
132140

133141
constructor(scope: Construct, id: string, props: ImagePipelineProps) {
134142
super(scope, id);
@@ -140,13 +148,13 @@ export class ImagePipeline extends Construct {
140148
const profileName = `${uid}Profile`;
141149

142150
// Construct code below
143-
const topic = new sns.Topic(this, 'ImageBuilderTopic', {
151+
this.builderSnsTopic = new sns.Topic(this, 'ImageBuilderTopic', {
144152
displayName: 'Image Builder Notify',
145153
masterKey: props.kmsKey,
146154
});
147155

148156
if (props.email != null) {
149-
topic.addSubscription(new subscriptions.EmailSubscription(props.email));
157+
this.builderSnsTopic.addSubscription(new subscriptions.EmailSubscription(props.email));
150158
}
151159

152160
const role = new iam.Role(this, 'Role', {
@@ -174,15 +182,15 @@ export class ImagePipeline extends Construct {
174182
name: `${uid}InfraConfig`,
175183
description: 'Example Infrastructure Configuration for Image Builder',
176184
instanceTypes: props.instanceTypes ?? ['t3.medium', 'm5.large', 'm5.xlarge'],
177-
snsTopicArn: topic.topicArn,
185+
snsTopicArn: this.builderSnsTopic.topicArn,
178186
});
179187
} else {
180188
infrastructureConfig = new imagebuilder.CfnInfrastructureConfiguration(this, 'InfrastructureConfiguration', {
181189
instanceProfileName: profileName,
182190
name: `${uid}InfraConfig`,
183191
description: 'Example Infrastructure Configuration for Image Builder',
184192
instanceTypes: props.instanceTypes ?? ['t3.medium', 'm5.large', 'm5.xlarge'],
185-
snsTopicArn: topic.topicArn,
193+
snsTopicArn: this.builderSnsTopic.topicArn,
186194
securityGroupIds: props.securityGroups,
187195
subnetId: props.subnetId,
188196
});
@@ -325,9 +333,9 @@ export class ImagePipeline extends Construct {
325333
},
326334
memorySize: 256,
327335
});
328-
amiSsmUpdateLambda.addEventSource(new SnsEventSource(topic, {}));
336+
amiSsmUpdateLambda.addEventSource(new SnsEventSource(this.builderSnsTopic, {}));
329337
}
330-
new imagebuilder.CfnImagePipeline(this, 'ImagePipeline', imagePipelineProps);
338+
this.pipeline = new imagebuilder.CfnImagePipeline(this, 'ImagePipeline', imagePipelineProps);
331339
}
332340

333341
/**

test/imagepipeline.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,17 @@ test('Image Pipeline has Inspector vulnerability scans configured', () => {
237237
},
238238
});
239239
});
240+
241+
242+
test('ImagePipeline exposes components as properties', () => {
243+
const app = new cdk.App();
244+
const testStack = new cdk.Stack(app, 'testStack', {
245+
env: {
246+
account: process.env.CDK_DEFAULT_ACCOUNT,
247+
region: process.env.CDK_DEFAULT_REGION,
248+
},
249+
});
250+
const sut = new ImagePipeline(testStack, 'ImagePipelineStack', props);
251+
expect(sut.pipeline).toBeDefined();
252+
expect(sut.builderSnsTopic).toBeDefined();
253+
});

0 commit comments

Comments
 (0)