Repository: awslabs/aws-ddk (ts)

Issue:
Configurator doesnt work as expected when using resource-ids
### Describe the bug

Configurator has 2 ways of working with either resource ids or globally using service like AWS::Lambda::Function. The former is needed to ensure each instance of resource can be given distinctive attributes if needed. Currently if resource id is used, it will be added to all resources in the stack even though its specified for a single id. It leads to errors as some resource might not even support that attribute/parameter

### How to Reproduce

```
"environments": {
    "dev": {
      "account": "222222222222",
      "region": "us-east-1",
      "resources": {
        "AWS::Lambda::Function": {
          "MemorySize": 128,
          "Runtime": "python3.8"
        }
      },
      "tags": {"CostCenter": "2014"}
    },
```

The above works as expected

```

environments: {
      dev: {
        resources: {
          bucket-id-1: {
            BucketName: "my-exact-bucket-name-for-this-resource",
          },
          queue-id-1: {
            KmsMasterKeyId: "alias/aws/sqs",
          },
        },
      },
    },

```

In the above, Configurator will add BucketName parameter to all resource including the queue mentioned. Similarly it will also add the KmsMasterKeyId to all resource of stack including the bucket mentioned above


### Expected behavior

It should only add parameter to the specific resource id 

### Your project

_No response_

### Screenshots

_No response_

### Environment

```
Provide your `pip list` output, particularly the version of the AWS DDK library you used. Providing this information may significantly improve resolution times.
```


### OS

Mac

### Python version

3.9

### AWS DDK version

1.0.0b

### Additional context

_No response_

Pull request description:
feat: configuration by resource ids
### Relates
- Closes #278 

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


Patch:
diff --git a/src/config/configurator.ts b/src/config/configurator.ts
index 48739bc..fc0f8ab 100644
--- a/src/config/configurator.ts
+++ b/src/config/configurator.ts
@@ -116,7 +116,9 @@ class ConfiguratorAspect implements cdk.IAspect {
       node.addPropertyOverride(this.propertyName, this.propertyValue);
     }
 
-    if (this.resourceId && cdk.CfnResource.isCfnResource(node)) {
+    const nodePathItemRegex = new RegExp(`^(.*\/)?(${this.resourceId})(\/.*)?$`);
+
+    if (this.resourceId && cdk.CfnResource.isCfnResource(node) && nodePathItemRegex.test(node.node.path)) {
       node.addPropertyOverride(this.propertyName, this.propertyValue);
     }
   }


Test patch:
diff --git a/test/config.test.ts b/test/config.test.ts
index 285bf47..375b121 100644
--- a/test/config.test.ts
+++ b/test/config.test.ts
@@ -1,10 +1,11 @@
 import { assert } from "console";
 import path from "path";
 import * as cdk from "aws-cdk-lib";
-import { Template } from "aws-cdk-lib/assertions";
+import { Match, Template } from "aws-cdk-lib/assertions";
 import * as lambda from "aws-cdk-lib/aws-lambda";
 import * as s3 from "aws-cdk-lib/aws-s3";
 import * as sqs from "aws-cdk-lib/aws-sqs";
+import { Construct } from "constructs";
 
 import {
   Configurator,
@@ -58,6 +59,12 @@ test("Config Simple Override", () => {
 });
 
 test("Config Override By Id", () => {
+  class NestedStack extends cdk.Stack {
+    constructor(scope: Construct, id: string) {
+      super(scope, id);
+      new s3.Bucket(this, "AVeryLongBucketNameInsideANestedStack");
+    }
+  }
   const sampleConfig = {
     environments: {
       dev: {
@@ -65,6 +72,9 @@ test("Config Override By Id", () => {
           MyBucket: {
             BucketName: "my-exact-bucket-name-for-this-resource",
           },
+          AVeryLongBucketNameInsideANestedStack: {
+            BucketName: "override-bucket-name",
+          },
           MyQueue: {
             KmsMasterKeyId: "alias/aws/sqs",
           },
@@ -75,9 +85,8 @@ test("Config Override By Id", () => {
   const stack = new cdk.Stack();
   new s3.Bucket(stack, "MyBucket");
   new sqs.Queue(stack, "MyQueue");
-
+  new sqs.Queue(stack, "MyUnencryptedQueue");
   new Configurator(stack, sampleConfig, "dev");
-
   const template = Template.fromStack(stack);
   template.hasResourceProperties("AWS::S3::Bucket", {
     BucketName: "my-exact-bucket-name-for-this-resource",
@@ -85,6 +94,17 @@ test("Config Override By Id", () => {
   template.hasResourceProperties("AWS::SQS::Queue", {
     KmsMasterKeyId: "alias/aws/sqs",
   });
+  template.hasResourceProperties("AWS::SQS::Queue", {
+    KmsMasterKeyId: Match.absent(),
+  });
+
+  const app = new cdk.App();
+  const nestedStack = new NestedStack(app, "PlaceholderWithExcessivelyLongNameABCDEFGHIJFKLMNOPQRSTUVXXYZ");
+  new Configurator(nestedStack, sampleConfig, "dev");
+  const nestedTemplate = Template.fromStack(nestedStack);
+  nestedTemplate.hasResourceProperties("AWS::S3::Bucket", {
+    BucketName: "override-bucket-name",
+  });
 });
 
 test("Different values per environment", () => {