1+ import 'source-map-support/register' ;
2+ import * as cdk from 'aws-cdk-lib' ;
3+ import * as iam from 'aws-cdk-lib/aws-iam' ;
4+ import * as blueprints from '../lib' ;
5+ import { Construct } from 'constructs' ;
6+
7+ const app = new cdk . App ( ) ;
8+
9+ const account = process . env . CDK_DEFAULT_ACCOUNT ;
10+ const region = process . env . CDK_DEFAULT_REGION ;
11+
12+ // Stack that creates a role
13+ class RoleStack extends cdk . Stack {
14+ public readonly customRole : iam . Role ;
15+
16+ constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) {
17+ super ( scope , id , props ) ;
18+
19+ this . customRole = new iam . Role ( this , 'CustomRole' , {
20+ assumedBy : new iam . ServicePrincipal ( 'eks.amazonaws.com' ) ,
21+ managedPolicies : [
22+ iam . ManagedPolicy . fromAwsManagedPolicyName ( 'AmazonEKSClusterPolicy' )
23+ ]
24+ } ) ;
25+ }
26+ }
27+
28+ // Contrived addon that takes role from another stack
29+ class CustomRoleAddOn implements blueprints . ClusterAddOn {
30+ private role : iam . Role ;
31+
32+ constructor ( role : iam . Role ) {
33+ this . role = role ;
34+ }
35+
36+ deploy ( clusterInfo : blueprints . ClusterInfo ) : Promise < Construct > {
37+ console . log ( `Role ARN: ${ this . role . roleArn } ` ) ;
38+ console . log ( `Role Name: ${ this . role . roleName } ` ) ;
39+
40+ // Return a dummy construct
41+ return Promise . resolve ( new Construct ( clusterInfo . cluster , 'CustomRoleAddOn' ) ) ;
42+ }
43+ }
44+
45+ // Create role stack
46+ const roleStack = new RoleStack ( app , 'role-stack' , {
47+ env : { account, region }
48+ } ) ;
49+
50+ // Example customer issue reproduction:
51+ const addOns : Array < blueprints . ClusterAddOn > = [
52+ new CustomRoleAddOn ( roleStack . customRole )
53+ ] ;
54+
55+ const stack = blueprints . EksBlueprint . builder ( )
56+ . account ( account )
57+ . region ( region )
58+ . addOns ( ...addOns )
59+ . version ( "auto" )
60+ . build ( app , 'passing-constructs' ) ;
61+
62+ // Add dependency
63+ stack . addDependency ( roleStack ) ;
64+
65+ void stack ; // Keep for debugging
0 commit comments