Skip to content

Commit

Permalink
make instancetype configurable
Browse files Browse the repository at this point in the history
closes #420
  • Loading branch information
snowiow committed Jul 3, 2024
1 parent bbbf1a4 commit 6e358de
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/aurora-serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class BastionHostAuroraServerlessForward extends BastionHostForward {
serverTimeout: props.serverTimeout,
shouldPatch: props.shouldPatch,
cachedInContext: props.cachedInContext,
instanceType: props.instanceType,
});

if (props.iamUser !== undefined && props.resourceIdentifier !== undefined) {
Expand Down
8 changes: 7 additions & 1 deletion lib/bastion-host-forward-base-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

import type { ISecurityGroup, IVpc } from 'aws-cdk-lib/aws-ec2';
import type { InstanceType, ISecurityGroup, IVpc } from 'aws-cdk-lib/aws-ec2';

export interface BastionHostForwardBaseProps {
/**
Expand Down Expand Up @@ -75,4 +75,10 @@ export interface BastionHostForwardBaseProps {
* @default false
*/
readonly cachedInContext?: boolean;

/**
* Type of instance to launch
* @default 't4g.nano'
*/
readonly instanceType?: InstanceType;
}
2 changes: 1 addition & 1 deletion lib/bastion-host-forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class BastionHostForward extends Construct {
generation: AmazonLinuxGeneration.AMAZON_LINUX_2023,
cachedInContext: props.cachedInContext,
}),
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
instanceType: props.instanceType ?? InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
blockDevices: [
{
deviceName: '/dev/xvda',
Expand Down
1 change: 1 addition & 0 deletions lib/generic-bastion-host-forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class GenericBastionHostForward extends BastionHostForward {
serverTimeout: props.serverTimeout,
shouldPatch: props.shouldPatch,
cachedInContext: props.cachedInContext,
instanceType: props.instanceType,
});
}
}
27 changes: 26 additions & 1 deletion test/aurora-serverless.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import { Template } from 'aws-cdk-lib/assertions';
import { strict as assert } from 'assert';
import { App, Stack } from 'aws-cdk-lib';
import { SecurityGroup, Vpc } from 'aws-cdk-lib/aws-ec2';
import { InstanceClass, InstanceSize, InstanceType, SecurityGroup, Vpc } from 'aws-cdk-lib/aws-ec2';
import { DatabaseClusterEngine, ServerlessCluster } from 'aws-cdk-lib/aws-rds';
import { BastionHostAuroraServerlessForward } from '../lib/aurora-serverless';

Expand Down Expand Up @@ -208,3 +208,28 @@ test('Bastion Host with own securityGroup', () => {
assert.equal(securityGroup.securityGroupId, bastionHostSecurityGroup.securityGroupId);
assert.equal(securityGroup.allowAllOutbound, bastionHostSecurityGroup.allowAllOutbound);
});

test('Bastion Host with different instanceType', () => {
const app = new App();
const stack = new Stack(app, 'TestStack');
const testVpc = new Vpc(stack, 'TestVpc');
const testAurora = new ServerlessCluster(stack, 'TestAurora', {
engine: DatabaseClusterEngine.AURORA,
vpc: testVpc,
});

// WHEN
new BastionHostAuroraServerlessForward(stack, 'MyTestConstruct', {
vpc: testVpc,
name: 'MyBastion',
serverlessCluster: testAurora,
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.MEDIUM),
});

const template = Template.fromStack(stack);

// THEN
template.hasResourceProperties('AWS::EC2::Instance', {
InstanceType: 't3.medium',
});
});
15 changes: 11 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"declaration": true,
"experimentalDecorators": true,
"incremental": true,
"lib": ["es2020"],
"lib": [
"es2020"
],
"module": "CommonJS",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
Expand All @@ -26,7 +28,12 @@
"composite": false,
"tsBuildInfoFile": "tsconfig.tsbuildinfo"
},
"include": ["**/*.ts"],
"exclude": ["node_modules", ".types-compat"],
"include": [
"**/*.ts"
],
"exclude": [
"node_modules",
".types-compat"
],
"_generated_by_jsii_": "Generated by jsii - safe to delete, and ideally should be in .gitignore"
}
}

0 comments on commit 6e358de

Please sign in to comment.