11import * as path from 'path' ;
22import * as integ from '@aws-cdk/integ-tests-alpha' ;
33import { App , Stack } from 'aws-cdk-lib' ;
4+ import { Template } from 'aws-cdk-lib/assertions' ;
45import * as lambda from 'aws-cdk-lib/aws-lambda' ;
56import { BucketEncryption } from 'aws-cdk-lib/aws-s3' ;
67import { APP_ID_MAX } from './util' ;
@@ -9,13 +10,34 @@ import { AppStagingSynthesizer } from '../lib';
910// IMAGE_COPIES env variable is used to test maximum number of ECR repositories allowed.
1011const IMAGE_COPIES = Number ( process . env . IMAGE_COPIES ) ?? 1 ;
1112
13+ // Test with custom qualifier
14+ const CUSTOM_QUALIFIER = 'custom-qualifier' ;
15+
1216const app = new App ( {
1317 context : {
1418 '@aws-cdk/aws-iam:minimizePolicies' : true ,
1519 '@aws-cdk/aws-lambda:useCdkManagedLogGroup' : false ,
1620 } ,
1721} ) ;
1822
23+ // Stack with custom qualifier
24+ const stackWithQualifier = new Stack ( app , 'synthesize-with-qualifier' , {
25+ synthesizer : AppStagingSynthesizer . defaultResources ( {
26+ appId : APP_ID_MAX ,
27+ bootstrapQualifier : CUSTOM_QUALIFIER ,
28+ stagingBucketEncryption : BucketEncryption . KMS ,
29+ } ) ,
30+ } ) ;
31+
32+ // Add a lambda to trigger asset creation
33+ new lambda . Function ( stackWithQualifier , 'lambda-with-qualifier' , {
34+ code : lambda . AssetCode . fromAsset ( path . join ( __dirname , 'assets' ) ) ,
35+ handler : 'index.handler' ,
36+ runtime : lambda . Runtime . PYTHON_3_10 ,
37+ } ) ;
38+
39+ // Default stack without qualifier
40+
1941const stack = new Stack ( app , 'synthesize-default-resources' , {
2042 synthesizer : AppStagingSynthesizer . defaultResources ( {
2143 appId : APP_ID_MAX , // this has implications on the overall template size
@@ -57,13 +79,27 @@ new lambda.Function(stack, 'lambda-ecr-two', {
5779 runtime : lambda . Runtime . FROM_IMAGE ,
5880} ) ;
5981
82+ // Get both staging stacks
6083const defaultStagingStack = app . node . tryFindChild ( `StagingStack-${ APP_ID_MAX } -ACCOUNT-REGION` ) as Stack ;
61- if ( ! defaultStagingStack ) {
62- throw new Error ( 'Default Staging Stack not found' ) ;
84+ const qualifierStagingStack = app . node . tryFindChild ( `StagingStack-${ CUSTOM_QUALIFIER } -ACCOUNT-REGION` ) as Stack ;
85+
86+ if ( ! defaultStagingStack || ! qualifierStagingStack ) {
87+ throw new Error ( 'One or more staging stacks not found' ) ;
6388}
6489
90+ // Add assertions to verify qualifier usage
6591new integ . IntegTest ( app , 'integ-tests' , {
66- testCases : [ stack , defaultStagingStack ] ,
92+ testCases : [ stack , stackWithQualifier , defaultStagingStack , qualifierStagingStack ] ,
93+ diffAssets : true ,
94+ } ) ;
95+
96+ // Verify qualifier is used in role names
97+ Template . fromStack ( qualifierStagingStack ) . hasResourceProperties ( 'AWS::IAM::Role' , {
98+ RoleName : `cdk-${ CUSTOM_QUALIFIER } -deploy-role-ACCOUNT-REGION` ,
99+ } ) ;
100+
101+ Template . fromStack ( qualifierStagingStack ) . hasResourceProperties ( 'AWS::IAM::Role' , {
102+ RoleName : `cdk-${ CUSTOM_QUALIFIER } -file-role-REGION` ,
67103} ) ;
68104
69105app . synth ( ) ;
0 commit comments