Skip to content

Commit

Permalink
feat(aws-elasticsearch): Allowing upgrading an Amazon ES domain to a …
Browse files Browse the repository at this point in the history
…new version of Elasticsearch rather than replacing the entire domain resource.
  • Loading branch information
hassanazharkhan committed Dec 27, 2020
1 parent 32e9c23 commit 4082681
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ const prodDomain = new es.Domain(this, 'Domain', {
This creates an Elasticsearch cluster and automatically sets up log groups for
logging the domain logs and slow search logs.


Create a development cluster by simply specifying the version:

```ts
import * as es from '@aws-cdk/aws-elasticsearch';

const devDomain = new es.Domain(this, 'Domain', {
version: es.ElasticsearchVersion.V7_1,
});
```

Allowing upgrading an Amazon ES domain to a new version of Elasticsearch rather than replacing the entire domain resource.

```ts
import * as es from '@aws-cdk/aws-elasticsearch';

const devDomain = new es.Domain(this, 'Domain', {
version: es.ElasticsearchVersion.V7_9,
enableVersionUpgrade: true // defaults to false
});
```

## Importing existing domains

To import an existing domain into your CDK application, use the `Domain.fromDomainEndpoint` factory method.
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-elasticsearch/lib/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ export interface DomainProps {
* @default - false
*/
readonly useUnsignedBasicAuth?: boolean;

/**
* To upgrade an Amazon ES domain to a new version of Elasticsearch rather than replacing the entire
* domain resource, use the EnableVersionUpgrade update policy.
*
* @default - false
*/
readonly enableVersionUpgrade?: boolean;

}

/**
Expand Down Expand Up @@ -1541,6 +1550,13 @@ export class Domain extends DomainBase implements IDomain {
: undefined,
});

if (props.enableVersionUpgrade) {
this.domain.cfnOptions.updatePolicy = {
...this.domain.cfnOptions.updatePolicy,
enableVersionUpgrade: props.enableVersionUpgrade,
};
}

if (logGroupResourcePolicy) { this.domain.node.addDependency(logGroupResourcePolicy); }

if (props.domainName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.domainName); }
Expand Down
56 changes: 56 additions & 0 deletions packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable jest/expect-expect */
import '@aws-cdk/assert/jest';
import { ResourcePart } from '@aws-cdk/assert';
import { Metric, Statistic } from '@aws-cdk/aws-cloudwatch';
import { Subnet, Vpc, EbsDeviceVolumeType } from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
Expand Down Expand Up @@ -67,6 +69,60 @@ test('minimal example renders correctly', () => {
});
});

test('minimal example with resource props renders correctly', () => {
new Domain(stack, 'Domain', {
version: ElasticsearchVersion.V7_1,
enableVersionUpgrade: true,
});

expect(stack).toHaveResource('AWS::Elasticsearch::Domain', {
Properties: {
CognitoOptions: {
Enabled: false,
},
DomainEndpointOptions: {
EnforceHTTPS: false,
TLSSecurityPolicy: 'Policy-Min-TLS-1-0-2019-07',
},
EBSOptions: {
EBSEnabled: true,
VolumeSize: 10,
VolumeType: 'gp2',
},
ElasticsearchClusterConfig: {
DedicatedMasterEnabled: false,
InstanceCount: 1,
InstanceType: 'r5.large.elasticsearch',
ZoneAwarenessEnabled: false,
},
ElasticsearchVersion: '7.1',
EncryptionAtRestOptions: {
Enabled: false,
},
LogPublishingOptions: {
AUDIT_LOGS: {
Enabled: false,
},
ES_APPLICATION_LOGS: {
Enabled: false,
},
SEARCH_SLOW_LOGS: {
Enabled: false,
},
INDEX_SLOW_LOGS: {
Enabled: false,
},
},
NodeToNodeEncryptionOptions: {
Enabled: false,
},
},
UpdatePolicy: {
EnableVersionUpgrade: true,
},
}, ResourcePart.CompleteDefinition);
});

describe('log groups', () => {

test('slowSearchLogEnabled should create a custom log group', () => {
Expand Down

0 comments on commit 4082681

Please sign in to comment.