Skip to content

Commit

Permalink
fix(rds): fix unresolved endpoint socket address
Browse files Browse the repository at this point in the history
Convert port to a string token before using it in `socketAddress` otherwise the number token is
converted to a string and cannot be resolved.

Fixes #2711
  • Loading branch information
jogold committed Jun 12, 2019
1 parent b80ef04 commit a3c3c3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-rds/lib/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Endpoint {
this.hostname = address;
this.port = port;

const portDesc = Token.isUnresolved(port) ? '{IndirectPort}' : port;
const portDesc = Token.isUnresolved(port) ? Token.asString(port) : port;
this.socketAddress = `${address}:${portDesc}`;
}
}
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-rds/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,37 @@ export = {
statistic: 'Average'
});

test.done();
},

'can resolve endpoint port and socket address'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
const instance = new rds.DatabaseInstance(stack, 'Instance', {
engine: rds.DatabaseInstanceEngine.Mysql,
instanceClass: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Small),
masterUsername: 'admin',
vpc
});

test.deepEqual(stack.resolve(instance.instanceEndpoint.port), {
'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Port']
});

test.deepEqual(stack.resolve(instance.instanceEndpoint.socketAddress), {
'Fn::Join': [
'',
[
{ 'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Address'] },
':',
{ 'Fn::GetAtt': ['InstanceC1063A87', 'Endpoint.Port'] },
]
]
});

test.done();
}
};

0 comments on commit a3c3c3a

Please sign in to comment.