Skip to content

Commit 01708bc

Browse files
authored
feat(cloud9): configure Connection Type of Ec2Environment (#20250)
Fixes #17027. Adds `connectionType` property to the L2 Construct `cloud9.Ec2Environment`. For the connection type an enum was implemented which is either `"CONNECT_SSH` or `CONNECT_SSM`. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d0163f8 commit 01708bc

File tree

9 files changed

+1382
-1
lines changed

9 files changed

+1382
-1
lines changed

packages/@aws-cdk/aws-cloud9/lib/environment.ts

+24
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ export interface IEc2Environment extends cdk.IResource {
2424
readonly ec2EnvironmentArn: string;
2525
}
2626

27+
/**
28+
* The connection type used for connecting to an Amazon EC2 environment.
29+
*/
30+
export enum ConnectionType {
31+
/**
32+
* Conect through SSH
33+
*/
34+
CONNECT_SSH = 'CONNECT_SSH',
35+
/**
36+
* Connect through AWS Systems Manager
37+
*/
38+
CONNECT_SSM = 'CONNECT_SSM'
39+
}
40+
2741
/**
2842
* Properties for Ec2Environment
2943
*/
@@ -70,6 +84,15 @@ export interface Ec2EnvironmentProps {
7084
*/
7185
// readonly clonedRepositories?: Cloud9Repository[];
7286
readonly clonedRepositories?: CloneRepository[];
87+
88+
/**
89+
* The connection type used for connecting to an Amazon EC2 environment.
90+
*
91+
* Valid values are: CONNECT_SSH (default) and CONNECT_SSM (connected through AWS Systems Manager)
92+
*
93+
* @default - CONNECT_SSH
94+
*/
95+
readonly connectionType?: ConnectionType
7396
}
7497

7598
/**
@@ -139,6 +162,7 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
139162
repositoryUrl: r.repositoryUrl,
140163
pathComponent: r.pathComponent,
141164
})) : undefined,
165+
connectionType: props.connectionType ?? ConnectionType.CONNECT_SSH,
142166
});
143167
this.environmentId = c9env.ref;
144168
this.ec2EnvironmentArn = c9env.getAtt('Arn').toString();

packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Template } from '@aws-cdk/assertions';
1+
import { Match, Template } from '@aws-cdk/assertions';
22
import * as codecommit from '@aws-cdk/aws-codecommit';
33
import * as ec2 from '@aws-cdk/aws-ec2';
44
import * as cdk from '@aws-cdk/core';
55
import * as cloud9 from '../lib';
6+
import { ConnectionType } from '../lib';
67

78
let stack: cdk.Stack;
89
let vpc: ec2.IVpc;
@@ -105,3 +106,20 @@ test('can use CodeCommit repositories', () => {
105106
],
106107
});
107108
});
109+
110+
test.each([
111+
[ConnectionType.CONNECT_SSH, 'CONNECT_SSH'],
112+
[ConnectionType.CONNECT_SSM, 'CONNECT_SSM'],
113+
[undefined, 'CONNECT_SSH'],
114+
])('has connection type property (%s)', (connectionType, expected) => {
115+
new cloud9.Ec2Environment(stack, 'C9Env', {
116+
vpc,
117+
connectionType,
118+
});
119+
120+
Template.fromStack(stack).hasResourceProperties('AWS::Cloud9::EnvironmentEC2', {
121+
InstanceType: Match.anyValue(),
122+
ConnectionType: expected,
123+
SubnetId: Match.anyValue(),
124+
});
125+
});

packages/@aws-cdk/aws-cloud9/test/cloud9.integ.snapshot/C9Stack.template.json

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@
360360
"C9EnvF05FC3BE": {
361361
"Type": "AWS::Cloud9::EnvironmentEC2",
362362
"Properties": {
363+
"ConnectionType": "CONNECT_SSH",
363364
"InstanceType": "t2.micro",
364365
"Repositories": [
365366
{

0 commit comments

Comments
 (0)