Skip to content

Commit

Permalink
fix(opensearchservice): imported domain's domainendpoint is a url n…
Browse files Browse the repository at this point in the history
…ot an endpoint (#18027)

imported Domain's domainEndpoint should be a endpoint and not a url.
Fixes [#18017](#18017)

BREAKING CHANGE: imported domain property `domainEndpoint` used to contain `https://` prefix, now the prefix is dropped and it returns the same value as a `domainEndpoint` on a created domain

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
joejegan authored Dec 21, 2021
1 parent a6dde1e commit fd149b1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-elasticsearch/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
return new class extends DomainBase {
public readonly domainArn = domainArn;
public readonly domainName = domainName;
public readonly domainEndpoint = domainEndpoint;
public readonly domainEndpoint = domainEndpoint.replace(/^https?:\/\//, '');

constructor() { super(scope, id); }
};
Expand Down
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,26 +928,30 @@ describe('import', () => {

test('static fromDomainEndpoint(endpoint) allows importing an external/existing domain', () => {
const domainName = 'test-domain-2w2x2u3tifly';
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
const imported = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint);

expect(imported.domainName).toEqual(domainName);
expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`));
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);

expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain');
});

test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => {
const domainName = 'test-domain-2w2x2u3tifly';
const domainArn = `arn:aws:es:testregion:1234:domain/${domainName}`;
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
const imported = Domain.fromDomainAttributes(stack, 'Domain', {
domainArn,
domainEndpoint,
});

expect(imported.domainName).toEqual(domainName);
expect(imported.domainArn).toEqual(domainArn);
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);

expect(stack).not.toHaveResource('AWS::Elasticsearch::Domain');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-opensearchservice/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable {
public readonly domainArn = domainArn;
public readonly domainName = domainName;
public readonly domainId = domainName;
public readonly domainEndpoint = domainEndpoint;
public readonly domainEndpoint = domainEndpoint.replace(/^https?:\/\//, '');

constructor() { super(scope, id); }
};
Expand Down
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-opensearchservice/test/domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,26 +930,30 @@ describe('import', () => {

test('static fromDomainEndpoint(endpoint) allows importing an external/existing domain', () => {
const domainName = 'test-domain-2w2x2u3tifly';
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
const imported = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint);

expect(imported.domainName).toEqual(domainName);
expect(imported.domainArn).toMatch(RegExp(`es:testregion:1234:domain/${domainName}$`));
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);

expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain');
});

test('static fromDomainAttributes(attributes) allows importing an external/existing domain', () => {
const domainName = 'test-domain-2w2x2u3tifly';
const domainArn = `arn:aws:es:testregion:1234:domain/${domainName}`;
const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpointWithoutHttps = `${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`;
const domainEndpoint = `https://${domainEndpointWithoutHttps}`;
const imported = Domain.fromDomainAttributes(stack, 'Domain', {
domainArn,
domainEndpoint,
});

expect(imported.domainName).toEqual(domainName);
expect(imported.domainArn).toEqual(domainArn);
expect(imported.domainEndpoint).toEqual(domainEndpointWithoutHttps);

expect(stack).not.toHaveResource('AWS::OpenSearchService::Domain');
});
Expand Down

0 comments on commit fd149b1

Please sign in to comment.