diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/private-dns-namespace.ts b/packages/@aws-cdk/aws-servicediscovery/lib/private-dns-namespace.ts index c5b8332c3238c..baf40ca47176f 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/private-dns-namespace.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/private-dns-namespace.ts @@ -61,6 +61,11 @@ export class PrivateDnsNamespace extends Resource implements IPrivateDnsNamespac */ public readonly namespaceArn: string; + /** + * ID of hosted zone created by namespace + */ + public readonly namespaceHostedZoneId: string; + /** * Type of the namespace. */ @@ -81,6 +86,7 @@ export class PrivateDnsNamespace extends Resource implements IPrivateDnsNamespac this.namespaceName = props.name; this.namespaceId = ns.attrId; this.namespaceArn = ns.attrArn; + this.namespaceHostedZoneId = ns.attrHostedZoneId; this.type = NamespaceType.DNS_PRIVATE; } diff --git a/packages/@aws-cdk/aws-servicediscovery/lib/public-dns-namespace.ts b/packages/@aws-cdk/aws-servicediscovery/lib/public-dns-namespace.ts index 431befda4c22d..5c18dce44bacf 100644 --- a/packages/@aws-cdk/aws-servicediscovery/lib/public-dns-namespace.ts +++ b/packages/@aws-cdk/aws-servicediscovery/lib/public-dns-namespace.ts @@ -53,6 +53,11 @@ export class PublicDnsNamespace extends Resource implements IPublicDnsNamespace */ public readonly namespaceArn: string; + /** + * ID of hosted zone created by namespace + */ + public readonly namespaceHostedZoneId: string; + /** * Type of the namespace. */ @@ -69,6 +74,7 @@ export class PublicDnsNamespace extends Resource implements IPublicDnsNamespace this.namespaceName = props.name; this.namespaceId = ns.attrId; this.namespaceArn = ns.attrArn; + this.namespaceHostedZoneId = ns.attrHostedZoneId; this.type = NamespaceType.DNS_PUBLIC; } diff --git a/packages/@aws-cdk/aws-servicediscovery/test/namespace.test.ts b/packages/@aws-cdk/aws-servicediscovery/test/namespace.test.ts index 30ccf20fc85f1..eb5d9f920acef 100644 --- a/packages/@aws-cdk/aws-servicediscovery/test/namespace.test.ts +++ b/packages/@aws-cdk/aws-servicediscovery/test/namespace.test.ts @@ -1,6 +1,7 @@ import { Template } from '@aws-cdk/assertions'; import * as ec2 from '@aws-cdk/aws-ec2'; import * as cdk from '@aws-cdk/core'; +import { CfnOutput } from '@aws-cdk/core'; import * as servicediscovery from '../lib'; describe('namespace', () => { @@ -64,4 +65,73 @@ describe('namespace', () => { }); + + test('CloudFormation attributes', () => { + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'MyVpc'); + + const privateNs = new servicediscovery.PrivateDnsNamespace(stack, 'MyPrivateNamespace', { + name: 'foobar.com', + vpc, + }); + const publicNs = new servicediscovery.PrivateDnsNamespace(stack, 'MyPublicNamespace', { + name: 'foobar.com', + vpc, + }); + new CfnOutput(stack, 'PrivateNsId', { value: privateNs.namespaceId }); + new CfnOutput(stack, 'PrivateNsArn', { value: privateNs.namespaceArn }); + new CfnOutput(stack, 'PrivateHostedZoneId', { value: privateNs.namespaceHostedZoneId }); + new CfnOutput(stack, 'PublicNsId', { value: publicNs.namespaceId }); + new CfnOutput(stack, 'PublicNsArn', { value: publicNs.namespaceArn }); + new CfnOutput(stack, 'PublicHostedZoneId', { value: publicNs.namespaceHostedZoneId }); + + Template.fromStack(stack).hasOutput('PrivateNsId', { + Value: { + 'Fn::GetAtt': [ + 'MyPrivateNamespace8CB3AE39', + 'Id', + ], + }, + }); + Template.fromStack(stack).hasOutput('PrivateNsArn', { + Value: { + 'Fn::GetAtt': [ + 'MyPrivateNamespace8CB3AE39', + 'Arn', + ], + }, + }); + Template.fromStack(stack).hasOutput('PrivateHostedZoneId', { + Value: { + 'Fn::GetAtt': [ + 'MyPrivateNamespace8CB3AE39', + 'HostedZoneId', + ], + }, + }); + Template.fromStack(stack).hasOutput('PublicNsId', { + Value: { + 'Fn::GetAtt': [ + 'MyPublicNamespaceAB66AFAC', + 'Id', + ], + }, + }); + Template.fromStack(stack).hasOutput('PublicNsArn', { + Value: { + 'Fn::GetAtt': [ + 'MyPublicNamespaceAB66AFAC', + 'Arn', + ], + }, + }); + Template.fromStack(stack).hasOutput('PublicHostedZoneId', { + Value: { + 'Fn::GetAtt': [ + 'MyPublicNamespaceAB66AFAC', + 'HostedZoneId', + ], + }, + }); + }); });