diff --git a/README.md b/README.md index a9e1ad5c113..c199cb0ba47 100644 --- a/README.md +++ b/README.md @@ -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`| @@ -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. diff --git a/bin/app.ts b/bin/app.ts index 6b0d9b0f9f5..8cb7f693235 100644 --- a/bin/app.ts +++ b/bin/app.ts @@ -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;