Skip to content

Commit

Permalink
feat(cloud9): configure Connection Type of Ec2Environment (#20250)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
daschaa committed May 19, 2022
1 parent d0163f8 commit 01708bc
Show file tree
Hide file tree
Showing 9 changed files with 1,382 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/@aws-cdk/aws-cloud9/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ export interface IEc2Environment extends cdk.IResource {
readonly ec2EnvironmentArn: string;
}

/**
* The connection type used for connecting to an Amazon EC2 environment.
*/
export enum ConnectionType {
/**
* Conect through SSH
*/
CONNECT_SSH = 'CONNECT_SSH',
/**
* Connect through AWS Systems Manager
*/
CONNECT_SSM = 'CONNECT_SSM'
}

/**
* Properties for Ec2Environment
*/
Expand Down Expand Up @@ -70,6 +84,15 @@ export interface Ec2EnvironmentProps {
*/
// readonly clonedRepositories?: Cloud9Repository[];
readonly clonedRepositories?: CloneRepository[];

/**
* The connection type used for connecting to an Amazon EC2 environment.
*
* Valid values are: CONNECT_SSH (default) and CONNECT_SSM (connected through AWS Systems Manager)
*
* @default - CONNECT_SSH
*/
readonly connectionType?: ConnectionType
}

/**
Expand Down Expand Up @@ -139,6 +162,7 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
repositoryUrl: r.repositoryUrl,
pathComponent: r.pathComponent,
})) : undefined,
connectionType: props.connectionType ?? ConnectionType.CONNECT_SSH,
});
this.environmentId = c9env.ref;
this.ec2EnvironmentArn = c9env.getAtt('Arn').toString();
Expand Down
20 changes: 19 additions & 1 deletion packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Template } from '@aws-cdk/assertions';
import { Match, Template } from '@aws-cdk/assertions';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import * as cloud9 from '../lib';
import { ConnectionType } from '../lib';

let stack: cdk.Stack;
let vpc: ec2.IVpc;
Expand Down Expand Up @@ -105,3 +106,20 @@ test('can use CodeCommit repositories', () => {
],
});
});

test.each([
[ConnectionType.CONNECT_SSH, 'CONNECT_SSH'],
[ConnectionType.CONNECT_SSM, 'CONNECT_SSM'],
[undefined, 'CONNECT_SSH'],
])('has connection type property (%s)', (connectionType, expected) => {
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
connectionType,
});

Template.fromStack(stack).hasResourceProperties('AWS::Cloud9::EnvironmentEC2', {
InstanceType: Match.anyValue(),
ConnectionType: expected,
SubnetId: Match.anyValue(),
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
"C9EnvF05FC3BE": {
"Type": "AWS::Cloud9::EnvironmentEC2",
"Properties": {
"ConnectionType": "CONNECT_SSH",
"InstanceType": "t2.micro",
"Repositories": [
{
Expand Down
Loading

0 comments on commit 01708bc

Please sign in to comment.