Skip to content

Commit

Permalink
feat(elasticsearch): Support EnableVersionUpgrade update policy (aw…
Browse files Browse the repository at this point in the history
…s#12239)

See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-upgradeelasticsearchdomain

Closes [aws#12210](aws#12210)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
hassanazharkhan authored and flochaz committed Jan 5, 2021
1 parent 88983b4 commit 049262e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 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,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;

}

/**
Expand Down Expand Up @@ -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); }
Expand Down
15 changes: 15 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,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', () => {
Expand Down

0 comments on commit 049262e

Please sign in to comment.