From 049262ededed035f92cac6650882f7fa824befb7 Mon Sep 17 00:00:00 2001 From: Hassan Azhar <57677979+hassanazharkhan@users.noreply.github.com> Date: Sun, 27 Dec 2020 21:05:54 +0500 Subject: [PATCH] feat(elasticsearch): Support `EnableVersionUpgrade` update policy (#12239) See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-upgradeelasticsearchdomain Closes [#12210](https://github.com/aws/aws-cdk/issues/12210) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-elasticsearch/README.md | 11 +++++++++++ .../@aws-cdk/aws-elasticsearch/lib/domain.ts | 17 +++++++++++++++++ .../aws-elasticsearch/test/domain.test.ts | 15 +++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/packages/@aws-cdk/aws-elasticsearch/README.md b/packages/@aws-cdk/aws-elasticsearch/README.md index b678f3e8f025d..f6e94c7c62c49 100644 --- a/packages/@aws-cdk/aws-elasticsearch/README.md +++ b/packages/@aws-cdk/aws-elasticsearch/README.md @@ -37,6 +37,17 @@ const devDomain = new es.Domain(this, 'Domain', { }); ``` +To perform version upgrades without replacing the entire domain, specify the `enableVersionUpgrade` property. + +```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 +}); +``` + Create a production grade cluster by also specifying things like capacity and az distribution ```ts diff --git a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts index c6880e74c00ba..477edb5106a79 100644 --- a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts +++ b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts @@ -517,6 +517,16 @@ 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. + * + * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-upgradeelasticsearchdomain + * @default - false + */ + readonly enableVersionUpgrade?: boolean; + } /** @@ -1541,6 +1551,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..ccce4e0860c5c 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,19 @@ test('minimal example renders correctly', () => { }); }); +test('can enable version upgrade update policy', () => { + new Domain(stack, 'Domain', { + version: ElasticsearchVersion.V7_1, + enableVersionUpgrade: true, + }); + + expect(stack).toHaveResource('AWS::Elasticsearch::Domain', { + UpdatePolicy: { + EnableVersionUpgrade: true, + }, + }, ResourcePart.CompleteDefinition); +}); + describe('log groups', () => { test('slowSearchLogEnabled should create a custom log group', () => {