@@ -17,6 +17,14 @@ const IMAGE_RECIPE_SYMBOL = Symbol.for('@aws-cdk/aws-imagebuilder-alpha.ImageRec
1717 */
1818const LATEST_VERSION = 'x.x.x' ;
1919
20+ /**
21+ * The default version to use in the image recipe. When the recipe is updated, the `x` will be incremented off from
22+ * the latest recipe version that exists.
23+ *
24+ * @see https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-image-recipes.html
25+ */
26+ const DEFAULT_RECIPE_VERSION = '1.0.x' ;
27+
2028/**
2129 * An EC2 Image Builder Image Recipe.
2230 */
@@ -48,7 +56,7 @@ export interface IImageRecipe extends IRecipeBase {
4856 */
4957export interface ImageRecipeProps {
5058 /**
51- * The base image for customizations specified in the container recipe.
59+ * The base image for customizations specified in the image recipe.
5260 */
5361 readonly baseImage : BaseImage ;
5462
@@ -147,7 +155,7 @@ export interface ImageRecipeAttributes {
147155 /**
148156 * The version of the image recipe
149157 *
150- * @default - derived from containerRecipeArn . if a containerRecipeName is provided, the latest version, x.x.x, will
158+ * @default - derived from imageRecipeArn . if a imageRecipeName is provided, the latest version, x.x.x, will
151159 * be used
152160 */
153161 readonly imageRecipeVersion ?: string ;
@@ -237,17 +245,13 @@ export class ImageRecipe extends ImageRecipeBase {
237245 * underscores with hyphens.
238246 */
239247 public static fromImageRecipeAttributes ( scope : Construct , id : string , attrs : ImageRecipeAttributes ) : IImageRecipe {
240- if ( attrs . imageRecipeArn && ( attrs . imageRecipeName || attrs . imageRecipeVersion ) ) {
248+ if ( ! attrs . imageRecipeArn && ! attrs . imageRecipeName ) {
241249 throw new cdk . ValidationError (
242- 'an imageRecipeName and imageRecipeVersion cannot be provided when an imageRecipeArn is provided ' ,
250+ 'either imageRecipeArn or imageRecipeName must be provided to import a image recipe ' ,
243251 scope ,
244252 ) ;
245253 }
246254
247- if ( ! attrs . imageRecipeArn && ! attrs . imageRecipeName ) {
248- throw new cdk . ValidationError ( 'either imageRecipeArn or imageRecipeName is required' , scope ) ;
249- }
250-
251255 const imageRecipeArn =
252256 attrs . imageRecipeArn ??
253257 cdk . Stack . of ( scope ) . formatArn ( {
@@ -321,20 +325,23 @@ export class ImageRecipe extends ImageRecipeBase {
321325
322326 this . validateImageRecipeName ( ) ;
323327
324- this . addBlockDevices ( ...( props . blockDevices ?? [ ] ) ) ;
328+ this . addBlockDevice ( ...( props . blockDevices ?? [ ] ) ) ;
325329
326330 const components : CfnImageRecipe . ComponentConfigurationProperty [ ] | undefined = props . components ?. map (
327331 ( component ) => ( {
328332 componentArn : component . component . componentArn ,
329- ...( Object . keys ( component . parameters ?? { } ) . length && {
330- parameters : Object . entries ( component . parameters ! ) . map (
331- ( [ key , value ] ) : CfnImageRecipe . ComponentParameterProperty => ( { name : key , value : value . value } ) ,
333+ ...( component . parameters && {
334+ parameters : Object . entries ( component . parameters ) . map (
335+ ( [ name , param ] ) : CfnImageRecipe . ComponentParameterProperty => ( {
336+ name,
337+ value : param . value ,
338+ } ) ,
332339 ) ,
333340 } ) ,
334341 } ) ,
335342 ) ;
336343
337- const imageRecipeVersion = props . imageRecipeVersion ?? '1.0.x' ;
344+ const imageRecipeVersion = props . imageRecipeVersion ?? DEFAULT_RECIPE_VERSION ;
338345 const imageRecipe = new CfnImageRecipe ( this , 'Resource' , {
339346 name : this . physicalName ,
340347 version : imageRecipeVersion ,
@@ -362,10 +369,17 @@ export class ImageRecipe extends ImageRecipeBase {
362369 *
363370 * @param blockDevices The list of block devices to attach
364371 */
365- public addBlockDevices ( ...blockDevices : ec2 . BlockDevice [ ] ) : void {
372+ public addBlockDevice ( ...blockDevices : ec2 . BlockDevice [ ] ) : void {
366373 this . blockDevices . push ( ...blockDevices ) ;
367374 }
368375
376+ /**
377+ * Renders the input block devices, into the `BlockDeviceMapping[]` structure that CfnImageRecipe expects to receive.
378+ * This is rendered at synthesis time, as users can add additional block devices with `addBlockDevice`, after the
379+ * construct has been instantiated.
380+ *
381+ * @private
382+ */
369383 private renderBlockDevices ( ) : CfnImageRecipe . InstanceBlockDeviceMappingProperty [ ] | undefined {
370384 const blockDevices = this . blockDevices . map ( ( blockDevice ) : CfnImageRecipe . InstanceBlockDeviceMappingProperty => {
371385 const ebsDevice = blockDevice . volume . ebsDevice ;
@@ -380,18 +394,24 @@ export class ImageRecipe extends ImageRecipeBase {
380394 ...( ebsDevice ?. volumeType !== undefined && { volumeType : ebsDevice . volumeType } ) ,
381395 } ;
382396
383- const mappingEnabled = blockDevice . mappingEnabled ?? true ;
384397 return {
385398 deviceName : blockDevice . deviceName ,
386399 virtualName : blockDevice . volume . virtualName ,
387- ...( ! mappingEnabled && { noDevice : '' } ) ,
400+ ...( blockDevice . mappingEnabled === false && { noDevice : '' } ) ,
388401 ...( Object . keys ( ebs ) . length && { ebs } ) ,
389402 } ;
390403 } ) ;
391404
392405 return blockDevices . length ? blockDevices : undefined ;
393406 }
394407
408+ /**
409+ * Generates the additional instance configuration property into the `AdditionalInstanceConfiguration` type in the
410+ * CloudFormation L1 definition.
411+ *
412+ * @param props The props passed as input to the construct
413+ * @private
414+ */
395415 private buildAdditionalInstanceConfiguration (
396416 props : ImageRecipeProps ,
397417 ) : CfnImageRecipe . AdditionalInstanceConfigurationProperty | undefined {
0 commit comments