(cli): Allow setting values for nested context objects from the cli
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Description
The CDK `context.json` file allows for users to configure nested keys, which are very useful for setting different configurations per environment. For example, a user might have a context that looks like this
```json
{
"dev":{
"key0":0,
"key1": "foo"
},
"prod":{
"key0":0,
"key1": "foo"
}
}
```
Secrets from CI pipelines are usually injected via the cli, but right now it is impossible to inject keys anywhere other than the root of the context object.
### Use Case
Implementing this would allow for injecting secrets into nested objects via the cli. In the example above, I wanted to add a secret to the production environment to make the context look as follows:
```json
{
"dev":{
"key0":0,
"key1": "foo"
},
"prod":{
"key0":0,
"key1": "foo",
"mySecret": "mySecret"
}
}
```
### Proposed Solution
One possibility is to use a syntax similar to `jq`:
```bash
jq ".context.prod.mySecret=$SECRET"
```
Each dot implies accessing a nested element, much like in regular javascript. This could potentially break existing code since people might have keys with dots in the name.
### Other information
While it's possible to add new programs (like jq) to transform `cdk.json` into the appropriate format, it would just be a lot more convenient if the cli could handle this natively.
### Acknowledge
- [ ] I may be able to implement this feature request
- [X] This feature might incur a breaking change
Contributor guide
Research direction
No file, test, or entry point is named; start by locating the CDK CLI command that sets context values and its handling of root keys. Define how nested paths and keys containing dots should behave, then verify that setting prod.mySecret produces the requested context structure without breaking existing usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100