Skip to content

Commit

Permalink
feat(servicediscovery): add hostedzoneid as attribute to namespace (#…
Browse files Browse the repository at this point in the history
…20583)

related to #20510 

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
peterwoodworth authored Jun 20, 2022
1 parent ddb4766 commit 454d60f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}

Expand Down
70 changes: 70 additions & 0 deletions packages/@aws-cdk/aws-servicediscovery/test/namespace.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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',
],
},
});
});
});

0 comments on commit 454d60f

Please sign in to comment.