Skip to content

Commit 74a0e22

Browse files
author
Dennis Ruhe
committed
feat(neptune-alpha): add tests for publiclyAccessible property
1 parent deef50e commit 74a0e22

File tree

6 files changed

+108
-2
lines changed

6 files changed

+108
-2
lines changed

packages/@aws-cdk/aws-neptune-alpha/lib/cluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export interface DatabaseClusterProps {
407407
* @see DatabaseInstanceProps.publiclyAccessible
408408
* @see https://docs.aws.amazon.com/neptune/latest/userguide/neptune-public-endpoints.html
409409
*
410-
* @default false
410+
* @default - false
411411
*/
412412
readonly publiclyAccessible?: boolean;
413413
}

packages/@aws-cdk/aws-neptune-alpha/lib/instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export interface DatabaseInstanceProps {
416416
/**
417417
* Indicates whether the DB instance is publicly accessible.
418418
*
419-
* @default false
419+
* @default - false
420420
*/
421421
readonly publiclyAccessible?: boolean;
422422
}

packages/@aws-cdk/aws-neptune-alpha/test/cluster.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,41 @@ describe('DatabaseCluster', () => {
675675
});
676676
});
677677

678+
test('publiclyAccessible is enabled when configured', () => {
679+
// GIVEN
680+
const stack = testStack();
681+
const vpc = new ec2.Vpc(stack, 'VPC');
682+
683+
// WHEN
684+
new DatabaseCluster(stack, 'Cluster', {
685+
vpc,
686+
instanceType: InstanceType.R5_LARGE,
687+
publiclyAccessible: true,
688+
});
689+
690+
// THEN
691+
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBInstance', {
692+
PubliclyAccessible: true,
693+
});
694+
});
695+
696+
test('publiclyAccessible is not enabled when not configured', () => {
697+
// GIVEN
698+
const stack = testStack();
699+
const vpc = new ec2.Vpc(stack, 'VPC');
700+
701+
// WHEN
702+
new DatabaseCluster(stack, 'Cluster', {
703+
vpc,
704+
instanceType: InstanceType.R5_LARGE,
705+
});
706+
707+
// THEN
708+
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBInstance', {
709+
PubliclyAccessible: false,
710+
});
711+
});
712+
678713
test('cloudwatchLogsExports is enabled when configured', () => {
679714
// GIVEN
680715
const stack = testStack();

packages/@aws-cdk/aws-neptune-alpha/test/instance.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ describe('DatabaseInstance', () => {
125125
});
126126
});
127127

128+
test.each([true, false])('instance with publiclyAccessible', (publiclyAccessible) => {
129+
// GIVEN
130+
const stack = testStack();
131+
132+
// WHEN
133+
new DatabaseInstance(stack, 'Instance', {
134+
cluster: stack.cluster,
135+
instanceType: InstanceType.R5_LARGE,
136+
publiclyAccessible,
137+
});
138+
139+
// THEN
140+
Template.fromStack(stack).hasResourceProperties('AWS::Neptune::DBInstance', {
141+
PubliclyAccessible: publiclyAccessible,
142+
});
143+
});
144+
128145
test('instance type from CfnParameter', () => {
129146
// GIVEN
130147
const stack = testStack();

packages/@aws-cdk/aws-neptune-alpha/test/integ.cluster.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const cluster = new DatabaseCluster(stack, 'Database', {
4343
kmsKey,
4444
removalPolicy: cdk.RemovalPolicy.DESTROY,
4545
autoMinorVersionUpgrade: true,
46+
publiclyAccessible: true,
4647
cloudwatchLogsExports: [LogType.AUDIT],
4748
cloudwatchLogsRetention: logs.RetentionDays.ONE_MONTH,
4849
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
2+
import * as cdk from 'aws-cdk-lib';
3+
import * as integ from '@aws-cdk/integ-tests-alpha';
4+
import { DatabaseCluster, DatabaseInstance, InstanceType } from '../lib';
5+
import { ClusterParameterGroup, ParameterGroupFamily } from '../lib/parameter-group';
6+
7+
/*
8+
* Test creating a cluster without specifying engine version.
9+
* This defaults to engine version >= 1.4.0.0 and associated parameter group with family neptune1.4
10+
*
11+
* Stack verification steps:
12+
* * aws docdb describe-db-clusters --db-cluster-identifier <deployed db cluster identifier>
13+
*/
14+
15+
const app = new cdk.App();
16+
17+
const stack = new cdk.Stack(app, 'AutoMinorVersionUpgradeInstanceStack');
18+
19+
const vpc = new ec2.Vpc(stack, 'VPC', { maxAzs: 2, natGateways: 1 });
20+
21+
const clusterParameterGroup = new ClusterParameterGroup(stack, 'Params', {
22+
description: 'A nice parameter group',
23+
family: ParameterGroupFamily.NEPTUNE_1_4,
24+
parameters: {
25+
neptune_enable_audit_log: '1',
26+
neptune_query_timeout: '100000',
27+
},
28+
});
29+
30+
const cluster = new DatabaseCluster(stack, 'Database', {
31+
vpc,
32+
instanceType: InstanceType.R5_LARGE,
33+
clusterParameterGroup,
34+
removalPolicy: cdk.RemovalPolicy.DESTROY,
35+
});
36+
37+
new DatabaseInstance(stack, 'EnabledInstance', {
38+
cluster,
39+
instanceType: InstanceType.R5_LARGE,
40+
removalPolicy: cdk.RemovalPolicy.DESTROY,
41+
publiclyAccessible: true,
42+
});
43+
44+
new DatabaseInstance(stack, 'DisabledInstance', {
45+
cluster,
46+
instanceType: InstanceType.R5_LARGE,
47+
removalPolicy: cdk.RemovalPolicy.DESTROY,
48+
publiclyAccessible: false,
49+
});
50+
51+
new integ.IntegTest(app, 'PubliclyAccessibleInstanceInteg', {
52+
testCases: [stack],
53+
});

0 commit comments

Comments
 (0)