@@ -22,6 +22,7 @@ enables organizations to create and manage catalogs of products for their end us
2222- [ Product] ( #product )
2323 - [ Creating a product from a local asset] ( #creating-a-product-from-local-asset )
2424 - [ Creating a product from a stack] ( #creating-a-product-from-a-stack )
25+ - [ Creating a Product from a stack with a history of previous versions] ( #creating-a-product-from-a-stack-with-a-history-of-all-previous-versions )
2526 - [ Adding a product to a portfolio] ( #adding-a-product-to-a-portfolio )
2627- [ TagOptions] ( #tag-options )
2728- [ Constraints] ( #constraints )
@@ -184,6 +185,105 @@ const product = new servicecatalog.CloudFormationProduct(this, 'Product', {
184185});
185186```
186187
188+ ### Creating a Product from a stack with a history of previous versions
189+
190+ The default behavior of Service Catalog is to overwrite each product version upon deployment.
191+ This applies to Product Stacks as well, where only the latest changes to your Product Stack will
192+ be deployed.
193+ To keep a history of the revisions of a ProductStack available in Service Catalog,
194+ you would need to define a ProductStack for each historical copy.
195+
196+ You can instead create a ` ProductStackHistory ` to maintain snapshots of all previous versions.
197+ The ` ProductStackHistory ` can be created by passing the base ` productStack ` ,
198+ a ` currentVersionName ` for your current version and a ` locked ` boolean.
199+ The ` locked ` boolean which when set to true will prevent your ` currentVersionName `
200+ from being overwritten when there is an existing snapshot for that version.
201+
202+ ``` ts
203+ import * as s3 from ' @aws-cdk/aws-s3' ;
204+ import * as cdk from ' @aws-cdk/core' ;
205+
206+ class S3BucketProduct extends servicecatalog .ProductStack {
207+ constructor (scope : cdk .Construct , id : string ) {
208+ super (scope , id );
209+
210+ new s3 .Bucket (this , ' BucketProduct' );
211+ }
212+ }
213+
214+ const productStackHistory = new servicecatalog .ProductStackHistory (this , ' ProductStackHistory' , {
215+ productStack: new S3BucketProduct (this , ' S3BucketProduct' ),
216+ currentVersionName: ' v1' ,
217+ currentVersionLocked: true
218+ });
219+ ```
220+
221+ We can deploy the current version ` v1 ` by using ` productStackHistory.currentVersion() `
222+
223+ ``` ts
224+ import * as s3 from ' @aws-cdk/aws-s3' ;
225+ import * as cdk from ' @aws-cdk/core' ;
226+
227+ class S3BucketProduct extends servicecatalog .ProductStack {
228+ constructor (scope : cdk .Construct , id : string ) {
229+ super (scope , id );
230+
231+ new s3 .Bucket (this , ' BucketProductV2' );
232+ }
233+ }
234+
235+ const productStackHistory = new servicecatalog .ProductStackHistory (this , ' ProductStackHistory' , {
236+ productStack: new S3BucketProduct (this , ' S3BucketProduct' ),
237+ currentVersionName: ' v2' ,
238+ currentVersionLocked: true
239+ });
240+
241+ const product = new servicecatalog .CloudFormationProduct (this , ' MyFirstProduct' , {
242+ productName: " My Product" ,
243+ owner: " Product Owner" ,
244+ productVersions: [
245+ productStackHistory .currentVersion (),
246+ ],
247+ });
248+ ```
249+
250+ Using ` ProductStackHistory ` all deployed templates for the ProductStack will be written to disk,
251+ so that they will still be available in the future as the definition of the ` ProductStack ` subclass changes over time.
252+ ** It is very important** that you commit these old versions to source control as these versions
253+ determine whether a version has already been deployed and can also be deployed themselves.
254+
255+ After using ` ProductStackHistory ` to deploy version ` v1 ` of your ` ProductStack ` , we
256+ make changes to the ` ProductStack ` and update the ` currentVersionName ` to ` v2 ` .
257+ We still want our ` v1 ` version to still be deployed, so we reference it by calling ` productStackHistory.versionFromSnapshot('v1') ` .
258+
259+ ``` ts
260+ import * as s3 from ' @aws-cdk/aws-s3' ;
261+ import * as cdk from ' @aws-cdk/core' ;
262+
263+ class S3BucketProduct extends servicecatalog .ProductStack {
264+ constructor (scope : cdk .Construct , id : string ) {
265+ super (scope , id );
266+
267+ new s3 .Bucket (this , ' BucketProductV2' );
268+ }
269+ }
270+
271+ const productStackHistory = new servicecatalog .ProductStackHistory (this , ' ProductStackHistory' , {
272+ productStack: new S3BucketProduct (this , ' S3BucketProduct' ),
273+ currentVersionName: ' v2' ,
274+ currentVersionLocked: true
275+ });
276+
277+ const product = new servicecatalog .CloudFormationProduct (this , ' MyFirstProduct' , {
278+ productName: " My Product" ,
279+ owner: " Product Owner" ,
280+ productVersions: [
281+ productStackHistory .currentVersion (),
282+ productStackHistory .versionFromSnapshot (' v1' )
283+ ],
284+ });
285+ ```
286+
187287### Adding a product to a portfolio
188288
189289You add products to a portfolio to organize and distribute your catalog at scale. Adding a product to a portfolio creates an association,
0 commit comments