Skip to content

Commit 5859689

Browse files
committed
feat: Add in support for resourceModel to the CC API Context Provider
1 parent 29249ac commit 5859689

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/@aws-cdk/cloud-assembly-schema/lib/cloud-assembly/context-queries.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ export interface KeyContextQuery extends ContextLookupRoleOptions {
368368
* const x: CcApiContextQuery = {
369369
* typeName: 'AWS::Some::Type',
370370
* expectedMatchCount: 'exactly-one',
371+
* resourceModel: {SomeArn: 'arn:aws:....'},
371372
* propertiesToReturn: ['SomeProp'],
372373
* account: '11111111111',
373374
* region: 'us-east-1',
@@ -390,6 +391,17 @@ export interface CcApiContextQuery extends ContextLookupRoleOptions {
390391
*/
391392
readonly exactIdentifier?: string;
392393

394+
/**
395+
* The resource model to use to select the resources, using `ListResources`..
396+
*
397+
* This is needed for sub-resources where the parent Arn is required.
398+
*
399+
* See https://docs.aws.amazon.com/cloudcontrolapi/latest/userguide/resource-operations-list.html#resource-operations-list-containers
400+
*
401+
* @default - no resource Model is provided
402+
*/
403+
readonly resourceModel?: Record<string, unknown>;
404+
393405
/**
394406
* Returns any resources matching these properties, using `ListResources`.
395407
*

packages/@aws-cdk/toolkit-lib/lib/context-providers/cc-api-provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class CcApiContextProviderPlugin implements ContextProviderPlugin {
3939
resources = await this.getResource(cloudControl, args.typeName, args.exactIdentifier);
4040
} else if (args.propertyMatch) {
4141
// use listResource
42-
resources = await this.listResources(cloudControl, args.typeName, args.propertyMatch, args.expectedMatchCount);
42+
resources = await this.listResources(cloudControl, args.typeName, args.propertyMatch, args.expectedMatchCount, args.resourceModel);
4343
} else {
4444
throw new ContextProviderError(`Provider protocol error: neither exactIdentifier nor propertyMatch is specified in ${JSON.stringify(args)}.`);
4545
}
@@ -99,14 +99,17 @@ export class CcApiContextProviderPlugin implements ContextProviderPlugin {
9999
typeName: string,
100100
propertyMatch: Record<string, unknown>,
101101
expectedMatchCount?: CcApiContextQuery['expectedMatchCount'],
102+
resourceModel?: Record<string, unknown>
102103
): Promise<FoundResource[]> {
103104
try {
104105
const found: FoundResource[] = [];
105106
let nextToken: string | undefined = undefined;
107+
const resourceModelJSON: string | undefined = resourceModel ? JSON.stringify(resourceModel) : undefined;
106108

107109
do {
108110
const result = await cc.listResources({
109111
TypeName: typeName,
112+
ResourceModel: resourceModelJSON,
110113
MaxResults: 100,
111114
...nextToken ? { NextToken: nextToken } : {},
112115
});

0 commit comments

Comments
 (0)