@@ -9,6 +9,7 @@ import * as s3 from 'aws-cdk-lib/aws-s3'
9
9
import * as s3seeder from 'aws-cdk-lib/aws-s3-deployment'
10
10
import * as rds from 'aws-cdk-lib/aws-rds' ;
11
11
import * as ssm from 'aws-cdk-lib/aws-ssm' ;
12
+ import * as kms from 'aws-cdk-lib/aws-kms' ;
12
13
import * as eks from 'aws-cdk-lib/aws-eks' ;
13
14
import * as yaml from 'js-yaml' ;
14
15
import * as path from 'path' ;
@@ -31,6 +32,8 @@ import { CfnJson, RemovalPolicy, Fn, Duration, Stack, StackProps, CfnOutput } fr
31
32
import { readFileSync } from 'fs' ;
32
33
import 'ts-replace-all'
33
34
import { TreatMissingData , ComparisonOperator } from 'aws-cdk-lib/aws-cloudwatch' ;
35
+ import { KubectlLayer } from 'aws-cdk-lib/lambda-layer-kubectl' ;
36
+ import { Cloud9Environment } from './modules/core/cloud9' ;
34
37
35
38
export class Services extends Stack {
36
39
constructor ( scope : Construct , id : string , props ?: StackProps ) {
@@ -109,7 +112,8 @@ export class Services extends Stack {
109
112
}
110
113
// The VPC where all the microservices will be deployed into
111
114
const theVPC = new ec2 . Vpc ( this , 'Microservices' , {
112
- cidr : cidrRange ,
115
+ ipAddresses : ec2 . IpAddresses . cidr ( cidrRange ) ,
116
+ // cidr: cidrRange,
113
117
natGateways : 1 ,
114
118
maxAzs : 2
115
119
} ) ;
@@ -327,13 +331,16 @@ export class Services extends Stack {
327
331
parameterName : '/eks/petsite/EKSMasterRoleArn'
328
332
} )
329
333
334
+ const secretsKey = new kms . Key ( this , 'SecretsKey' ) ;
330
335
const cluster = new eks . Cluster ( this , 'petsite' , {
331
336
clusterName : 'PetSite' ,
332
337
mastersRole : clusterAdmin ,
333
338
vpc : theVPC ,
334
339
defaultCapacity : 2 ,
335
340
defaultCapacityInstance : ec2 . InstanceType . of ( ec2 . InstanceClass . T3 , ec2 . InstanceSize . MEDIUM ) ,
336
- version : KubernetesVersion . V1_23
341
+ secretsEncryptionKey : secretsKey ,
342
+ version : KubernetesVersion . of ( '1.27' ) ,
343
+ kubectlLayer : new KubectlLayer ( this , 'kubectl' )
337
344
} ) ;
338
345
339
346
const clusterSG = ec2 . SecurityGroup . fromSecurityGroupId ( this , 'ClusterSG' , cluster . clusterSecurityGroupId ) ;
@@ -448,9 +455,16 @@ export class Services extends Stack {
448
455
449
456
if ( isEventEngine === 'true' )
450
457
{
451
- var c9role = undefined
452
- var c9InstanceProfile = undefined
453
- var c9env = undefined
458
+
459
+ var c9Env = new Cloud9Environment ( this , 'Cloud9Environment' , {
460
+ vpcId : theVPC . vpcId ,
461
+ subnetId : theVPC . publicSubnets [ 0 ] . subnetId ,
462
+ cloud9OwnerArn : "assumed-role/WSParticipantRole/Participant" ,
463
+ templateFile : __dirname + "/../../../../cloud9-cfn.yaml"
464
+
465
+ } ) ;
466
+
467
+ var c9role = c9Env . c9Role ;
454
468
455
469
// Dynamically check if AWSCloud9SSMAccessRole and AWSCloud9SSMInstanceProfile exists
456
470
const c9SSMRole = new iam . Role ( this , 'AWSCloud9SSMAccessRole' , {
@@ -460,51 +474,15 @@ export class Services extends Stack {
460
474
managedPolicies : [ iam . ManagedPolicy . fromAwsManagedPolicyName ( "AWSCloud9SSMInstanceProfile" ) , iam . ManagedPolicy . fromAwsManagedPolicyName ( "AdministratorAccess" ) ]
461
475
} ) ;
462
476
463
- const c9SSMRoleNoPath = iam . Role . fromRoleArn ( this , 'c9SSMRoleNoPath' , "arn:aws:iam::" + stack . account + ":role/AWSCloud9SSMAccessRole" )
464
- cluster . awsAuth . addMastersRole ( c9SSMRoleNoPath ) ;
465
-
466
- new iam . CfnInstanceProfile ( this , 'AWSCloud9SSMInstanceProfile' , {
467
- path : '/cloud9/' ,
468
- roles : [ c9SSMRole . roleName ] ,
469
- instanceProfileName : 'AWSCloud9SSMInstanceProfile'
470
- } ) ;
471
-
472
- c9env = new cloud9 . CfnEnvironmentEC2 ( this , "CloudEnv" , {
473
- ownerArn : "arn:aws:iam::" + stack . account + ":assumed-role/WSParticipantRole/Participant" ,
474
- instanceType : "t2.micro" ,
475
- name : "observabilityworkshop" ,
476
- subnetId : theVPC . privateSubnets [ 0 ] . subnetId ,
477
- connectionType : 'CONNECT_SSM' ,
478
- repositories : [
479
- {
480
- repositoryUrl : "https://github.com/aws-samples/one-observability-demo.git" ,
481
- pathComponent : "workshopfiles/one-observability-demo"
482
- }
483
- ]
484
- } ) ;
485
-
486
- c9role = new iam . Role ( this , 'cloud9InstanceRole' , {
487
- assumedBy : new iam . ServicePrincipal ( "ec2.amazonaws.com" ) ,
488
- managedPolicies : [ iam . ManagedPolicy . fromAwsManagedPolicyName ( "AdministratorAccess" ) , iam . ManagedPolicy . fromAwsManagedPolicyName ( "AmazonSSMManagedInstanceCore" ) ] ,
489
- roleName : "observabilityworkshop-admin"
490
- } ) ;
491
-
492
- c9InstanceProfile = new iam . CfnInstanceProfile ( this , 'cloud9InstanceProfile' , {
493
- roles : [ c9role . roleName ] ,
494
- instanceProfileName : "observabilityworkshop-profile"
495
- } )
496
-
497
- const teamRole = iam . Role . fromRoleArn ( this , 'TeamRole' , "arn:aws:iam::" + stack . account + ":role/TeamRole" ) ;
477
+ const teamRole = iam . Role . fromRoleArn ( this , 'TeamRole' , "arn:aws:iam::" + stack . account + ":role/WSParticipantRole" ) ;
498
478
cluster . awsAuth . addRoleMapping ( teamRole , { groups :[ "dashboard-view" ] } ) ;
479
+
499
480
481
+ if ( c9role != undefined ) {
482
+ cluster . awsAuth . addMastersRole ( iam . Role . fromRoleArn ( this , 'c9role' , c9role . attrArn , { mutable : false } ) ) ;
483
+ }
500
484
501
485
502
- if ( c9role != undefined )
503
- cluster . awsAuth . addMastersRole ( c9role )
504
-
505
- if ( c9env != undefined )
506
- cluster . node . addDependency ( c9env )
507
-
508
486
}
509
487
510
488
const eksAdminArn = this . node . tryGetContext ( 'admin_role' ) ;
0 commit comments