Skip to content

Commit b3a4405

Browse files
committed
Merge branch 'c9upgrade' into 'main'
Cloud9 Upgrade to Ubuntu 22.04 See merge request observability-bd-projects/one-observability-demo!134
2 parents 7544441 + 696cf91 commit b3a4405

File tree

5 files changed

+465
-322
lines changed

5 files changed

+465
-322
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Construct } from "constructs";
2+
import * as cloudformation_include from "aws-cdk-lib/cloudformation-include";
3+
import { CfnRole } from "aws-cdk-lib/aws-iam";
4+
5+
export interface Cloud9EnvironmentProps {
6+
name?: string;
7+
vpcId: string;
8+
subnetId: string;
9+
templateFile: string;
10+
cloud9OwnerArn?: string;
11+
}
12+
13+
export class Cloud9Environment extends Construct {
14+
public readonly c9Role: CfnRole;
15+
constructor(scope: Construct, id: string, props: Cloud9EnvironmentProps) {
16+
super(scope, id);
17+
18+
const template = new cloudformation_include.CfnInclude(this, 'Cloud9Template', {
19+
templateFile: props.templateFile,
20+
parameters: {
21+
'CreateVPC': false,
22+
'Cloud9VPC': props.vpcId,
23+
'Cloud9Subnet': props.subnetId
24+
},
25+
preserveLogicalIds: false
26+
});
27+
28+
if (props.name) {
29+
template.getParameter("EnvironmentName").default = props.name;
30+
}
31+
32+
if (props.cloud9OwnerArn) {
33+
template.getParameter("Cloud9OwnerRole").default = props.cloud9OwnerArn.valueOf();
34+
}
35+
36+
this.c9Role = template.getResource("C9Role") as CfnRole;
37+
38+
}
39+
}

PetAdoptions/cdk/pet_stack/lib/services.ts

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { readFileSync } from 'fs';
3232
import 'ts-replace-all'
3333
import { TreatMissingData, ComparisonOperator } from 'aws-cdk-lib/aws-cloudwatch';
3434
import { KubectlLayer } from 'aws-cdk-lib/lambda-layer-kubectl';
35+
import { Cloud9Environment } from './modules/core/cloud9';
3536

3637
export 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');

PetAdoptions/envsetup.sh

Lines changed: 0 additions & 78 deletions
This file was deleted.

PetAdoptions/envsetup_ee.sh

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)