(core): Escape Hatches don't create array implicitly and don't delete elements from arrays
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
> Originally sent by a PS CDK SupportOps over Slack
According to the [Escape Hatches docs](https://docs.aws.amazon.com/cdk/latest/guide/cfn_layer.html) Raw overrides section, given the following java code:
```java
// use index (0 here) to address an element of a list
cfnBucket.addOverride("Properties.Tags.0.Value", "NewValue");
cfnBucket.addDeletionOverride("Properties.Tags.0");
```
I would expect the addOverride method to create an array with one element "NewValue" as Tags’ value. Especially given @nija-at 's example [here](https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/core/lib/cfn-resource.ts#L153-L176) but instead it creates a Tags object (see below).
### Reproduction Steps
```java
Bucket bucket = Bucket.Builder.create(this, "MyFirstBucket")
.bucketName("my-first-cdk-java-s3-bucket")
.versioned(true).build();
CfnBucket cfnBucket = (CfnBucket)bucket.getNode().getDefaultChild();
cfnBucket.addOverride("Properties.Tags.0.Value", "NewValue");
cfnBucket.addOverride("Properties.Tags.1.SecondValue", "NewValue");
```
### What did you expect to happen?
synthesized template:
```json
"MyFirstBucketB8884501": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "my-first-cdk-java-s3-bucket",
"Tags": [
{
"Value": "NewValue"
},
{
"SecondValue": "NewValue"
}
],
...
```
### What actually happened?
synthesized template:
```json
"MyFirstBucketB8884501": {
"Type": "AWS::S3::Bucket",
"Properties": {
"BucketName": "my-first-cdk-java-s3-bucket",
"Tags": {
"0": {
"Value": "NewValue"
},
"1": {
"SecondValue": "NewValue"
}
},
...
```
### Environment
- **CDK CLI Version:** 1.72.0
- **Framework Version:** N/A
- **Node.js Version:** v10.23.0
- **OS:** Amazon Linux
- **Language (Version):** All (tested in both Java and Typescript)
### Other
To force it to create an array if one doesn't exists, @eladb suggested using `addOverride` this way: `cfnBucket.addOverride("Properties.Tags", [ { "Value": "NewValue" }, { "SecondValue": "NewValue" } ]);` and that does create the Tags array correctly but then when using `cfnBucket.addDeletionOverride("Properties.Tags.0")`, as mentioned in the docs, it doesn’t delete the first Tag element but instead deletes the entire Tags array.
---
This is :bug: Bug Report
Contributor guide
Research direction
Start in packages/@aws-cdk/core/lib/cfn-resource.ts, referenced by the issue, and trace addOverride and addDeletionOverride with the dotted path examples. Reproduce the synthesized output for indexed paths and explicit arrays, then add coverage for implicit array creation and deleting one element; done means both operations match the documented behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100