Skip to content

Commit

Permalink
Add feature for contextKey value for nested context (opensearch-proje…
Browse files Browse the repository at this point in the history
…ct#126)

Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait authored Jun 17, 2024
1 parent 974b6f3 commit 65896f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ In order to deploy both the stacks the user needs to provide a set of required a

| Name | Requirement | Type | Description |
|-------------------------------|:------------|:----------|:------------|
| contextKey | Optional | string | A top-level key that the rest of the parameters can be nested within for organized configuration. This is used to parse config from a specific key in the `cdk.context.json` or in the `context` block in the `cdk.json` file. |
| distVersion | Required | string | The OpenSearch distribution version (released/un-released) the user wants to deploy |
| securityDisabled | Required | boolean | Enable or disable security plugin |
| adminPassword | Optionally required | string | This value is required when security plugin is enabled and the cluster version is greater or equal to `2.12.0`|
Expand Down Expand Up @@ -109,6 +110,26 @@ cdk synth "*" --context securityDisabled=false \
--context distVersion=2.3.0 --context serverAccessType=ipv4 --context restrictServerAccessTo=10.10.10.10/32
```

Alternatively, you can use the `contextKey` to provide the configuration.

For example, to synthesize the CloudFormation templates using a context key:
```sh
cdk synth "*" --context contextKey=devConfig
```
You would include the configuration in your `cdk.json` file like this:
```js
// cdk.json
{
"context": {
"devConfig": {
"securityDisabled": false,
// ...
}
}
}
```
This approach allows you to manage multiple configurations easily by defining different context keys for each environment.

#### Sample command to set up multi-node cluster with security enabled on x64 AL2 machine

Please note that as of now we only support instances backed by Amazon Linux-2 amis.
Expand Down
11 changes: 11 additions & 0 deletions bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import { InfraStack } from '../lib/infra/infra-stack';
import { NetworkStack } from '../lib/networking/vpc-stack';

const app = new App();

const contextKey = app.node.tryGetContext('contextKey');
if (contextKey) {
const nestedContext = app.node.tryGetContext(contextKey);
if (nestedContext && typeof nestedContext === 'object') {
Object.entries(nestedContext).forEach(([nestedKey, nestedValue]) => {
app.node.setContext(nestedKey, nestedValue);
});
}
}

const region = app.node.tryGetContext('region') ?? process.env.CDK_DEFAULT_REGION;
const account = app.node.tryGetContext('account') ?? process.env.CDK_DEFAULT_ACCOUNT;

Expand Down

0 comments on commit 65896f8

Please sign in to comment.