Skip to content

Commit

Permalink
Fix A_AAAA Dns record type
Browse files Browse the repository at this point in the history
  • Loading branch information
SoManyHs committed Feb 25, 2019
1 parent ed47a55 commit c284a09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
29 changes: 19 additions & 10 deletions packages/@aws-cdk/aws-servicediscovery/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export interface IService extends cdk.IConstruct {
readonly dnsRecordType: DnsRecordType;
}


/**
* Basic props needed to create a service in a given namespace. Used by HttpNamespace.createService
*/
Expand Down Expand Up @@ -170,16 +169,10 @@ export class Service extends cdk.Construct implements IService {
: RoutingPolicy.Multivalue;

const dnsRecordType = props.dnsRecordType !== undefined ? props.dnsRecordType : DnsRecordType.A;

const dnsConfig = props.namespace.type === NamespaceType.Http
? undefined
: {
dnsRecords: [
{
type: dnsRecordType,
ttl: props.dnsTtlSec !== undefined ? props.dnsTtlSec.toString() : '60',
}
],
dnsRecords: _getDnsRecords(dnsRecordType, props.dnsTtlSec),
namespaceId: props.namespace.namespaceId,
routingPolicy,
};
Expand Down Expand Up @@ -214,7 +207,23 @@ export class Service extends cdk.Construct implements IService {
this.serviceArn = service.serviceArn;
this.serviceId = service.serviceId;
this.namespace = props.namespace;
this.dnsRecordType = props.dnsRecordType || DnsRecordType.A;
this.dnsRecordType = dnsRecordType;
}
}

function _getDnsRecords(dnsRecordType: DnsRecordType, dnsTtlSec?: number): DnsRecord[] {
const ttl = dnsTtlSec !== undefined ? dnsTtlSec.toString() : '60';

if (dnsRecordType === DnsRecordType.A_AAAA) {
return [{
type: DnsRecordType.A,
ttl
}, {
type: DnsRecordType.AAAA,
ttl,
}];
} else {
return [ { type: dnsRecordType, ttl} ];
}
}

Expand Down Expand Up @@ -252,7 +261,7 @@ export interface DnsRecord {
/**
* The time to live for the record
*/
ttlSec: number;
ttl: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');
const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 });

const namespace = new servicediscovery.PrivateDnsNamespace(stack, 'Namespace', {
name: "foobar.com",
name: "woobar.com",
vpc,
});

new servicediscovery.Service(stack, 'Service', {
name: "frontend",
namespace,
dnsRecordType: servicediscovery.DnsRecordType.A_AAAA
namespace.createService('Service', {
name: "bloop",
dnsRecordType: servicediscovery.DnsRecordType.A_AAAA,
dnsTtlSec: 30,
healthCheckCustomConfig: { failureThreshold: 2 }
});

app.run();
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-servicediscovery/test/test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ export = {
DnsRecords: [
{
TTL: "60",
Type: "A, AAAA"
Type: "A"
},
{
TTL: "60",
Type: "AAAA"
}
],
NamespaceId: {
"Fn::GetAtt": [
Expand Down

0 comments on commit c284a09

Please sign in to comment.