@@ -32,6 +32,7 @@ import { readFileSync } from 'fs';
3232import 'ts-replace-all'
3333import { TreatMissingData , ComparisonOperator } from 'aws-cdk-lib/aws-cloudwatch' ;
3434import { KubectlLayer } from 'aws-cdk-lib/lambda-layer-kubectl' ;
35+ import { Cloud9Environment } from './modules/core/cloud9' ;
3536
3637export class Services extends Stack {
3738 constructor ( scope : Construct , id : string , props ?: StackProps ) {
@@ -451,9 +452,16 @@ export class Services extends Stack {
451452
452453 if ( isEventEngine === 'true' )
453454 {
454- var c9role = undefined
455- var c9InstanceProfile = undefined
456- var c9env = undefined
455+
456+ var c9Env = new Cloud9Environment ( this , 'Cloud9Environment' , {
457+ vpcId : theVPC . vpcId ,
458+ subnetId : theVPC . publicSubnets [ 0 ] . subnetId ,
459+ cloud9OwnerArn : "assumed-role/WSParticipantRole/Participant" ,
460+ templateFile : __dirname + "/../../../../cloud9-cfn.yaml"
461+
462+ } ) ;
463+
464+ var c9role = c9Env . c9Role ;
457465
458466 // Dynamically check if AWSCloud9SSMAccessRole and AWSCloud9SSMInstanceProfile exists
459467 const c9SSMRole = new iam . Role ( this , 'AWSCloud9SSMAccessRole' , {
@@ -463,51 +471,15 @@ export class Services extends Stack {
463471 managedPolicies : [ iam . ManagedPolicy . fromAwsManagedPolicyName ( "AWSCloud9SSMInstanceProfile" ) , iam . ManagedPolicy . fromAwsManagedPolicyName ( "AdministratorAccess" ) ]
464472 } ) ;
465473
466- const c9SSMRoleNoPath = iam . Role . fromRoleArn ( this , 'c9SSMRoleNoPath' , "arn:aws:iam::" + stack . account + ":role/AWSCloud9SSMAccessRole" )
467- cluster . awsAuth . addMastersRole ( c9SSMRoleNoPath ) ;
468-
469- new iam . CfnInstanceProfile ( this , 'AWSCloud9SSMInstanceProfile' , {
470- path : '/cloud9/' ,
471- roles : [ c9SSMRole . roleName ] ,
472- instanceProfileName : 'AWSCloud9SSMInstanceProfile'
473- } ) ;
474-
475- c9env = new cloud9 . CfnEnvironmentEC2 ( this , "CloudEnv" , {
476- ownerArn : "arn:aws:iam::" + stack . account + ":assumed-role/WSParticipantRole/Participant" ,
477- instanceType : "t2.micro" ,
478- name : "observabilityworkshop" ,
479- subnetId : theVPC . privateSubnets [ 0 ] . subnetId ,
480- connectionType : 'CONNECT_SSM' ,
481- repositories : [
482- {
483- repositoryUrl : "https://github.com/aws-samples/one-observability-demo.git" ,
484- pathComponent : "workshopfiles/one-observability-demo"
485- }
486- ]
487- } ) ;
488-
489- c9role = new iam . Role ( this , 'cloud9InstanceRole' , {
490- assumedBy : new iam . ServicePrincipal ( "ec2.amazonaws.com" ) ,
491- managedPolicies : [ iam . ManagedPolicy . fromAwsManagedPolicyName ( "AdministratorAccess" ) , iam . ManagedPolicy . fromAwsManagedPolicyName ( "AmazonSSMManagedInstanceCore" ) ] ,
492- roleName : "observabilityworkshop-admin"
493- } ) ;
494-
495- c9InstanceProfile = new iam . CfnInstanceProfile ( this , 'cloud9InstanceProfile' , {
496- roles : [ c9role . roleName ] ,
497- instanceProfileName : "observabilityworkshop-profile"
498- } )
499-
500- const teamRole = iam . Role . fromRoleArn ( this , 'TeamRole' , "arn:aws:iam::" + stack . account + ":role/TeamRole" ) ;
474+ const teamRole = iam . Role . fromRoleArn ( this , 'TeamRole' , "arn:aws:iam::" + stack . account + ":role/WSParticipantRole" ) ;
501475 cluster . awsAuth . addRoleMapping ( teamRole , { groups :[ "dashboard-view" ] } ) ;
476+
502477
478+ if ( c9role != undefined ) {
479+ cluster . awsAuth . addMastersRole ( iam . Role . fromRoleArn ( this , 'c9role' , c9role . attrArn , { mutable : false } ) ) ;
480+ }
503481
504482
505- if ( c9role != undefined )
506- cluster . awsAuth . addMastersRole ( c9role )
507-
508- if ( c9env != undefined )
509- cluster . node . addDependency ( c9env )
510-
511483 }
512484
513485 const eksAdminArn = this . node . tryGetContext ( 'admin_role' ) ;
0 commit comments