From 4082681c9fbd6c3c796673cabc4f16b2e991c11a Mon Sep 17 00:00:00 2001 From: Hassan Azhar Khan Date: Sun, 27 Dec 2020 07:44:51 +0500 Subject: [PATCH] feat(aws-elasticsearch): Allowing upgrading an Amazon ES domain to a new version of Elasticsearch rather than replacing the entire domain resource. --- packages/@aws-cdk/aws-elasticsearch/README.md | 22 ++++++++ .../@aws-cdk/aws-elasticsearch/lib/domain.ts | 16 ++++++ .../aws-elasticsearch/test/domain.test.ts | 56 +++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/packages/@aws-cdk/aws-elasticsearch/README.md b/packages/@aws-cdk/aws-elasticsearch/README.md index b678f3e8f025d..84d70b74f6bbd 100644 --- a/packages/@aws-cdk/aws-elasticsearch/README.md +++ b/packages/@aws-cdk/aws-elasticsearch/README.md @@ -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. diff --git a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts index c6880e74c00ba..76e534ddb3185 100644 --- a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts +++ b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts @@ -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; + } /** @@ -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); } diff --git a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts index c257a616506c3..6a686b354a371 100644 --- a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts +++ b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts @@ -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'; @@ -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', () => {