-
Notifications
You must be signed in to change notification settings - Fork 19
fix: override certain incorrect primary identifiers #2328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aws-cdk-automation
merged 7 commits into
main
from
huijbers/override-primary-identifiers
Dec 23, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff31f75
fix: override certain incorrect primary identifiers
rix0rrr 4c85d0e
It needs to be opt-in
rix0rrr 4deaadc
Should not have committed this
rix0rrr 0f907fb
Update docs
rix0rrr aff3bba
Add diffing
rix0rrr 68e0d73
Exercise code in test
rix0rrr 7b776e5
chore: self mutation
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/service-spec-importers/schemas/CfnPrimaryIdentifierOverrides.schema.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "$ref": "#/definitions/CfnPrimaryIdentifierOverrides", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "definitions": { | ||
| "CfnPrimaryIdentifierOverrides": { | ||
| "additionalProperties": { | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "type": "array" | ||
| }, | ||
| "description": "Maps a resource type to a list of properties that are overrides of the CCAPI schema primary identifiers", | ||
| "type": "object" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s/@aws-cdk/service-spec-importers/src/importers/import-cfn-primaryidentifier-overrides.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { SpecDatabase } from '@aws-cdk/service-spec-types'; | ||
| import { CfnPrimaryIdentifierOverrides } from '../types'; | ||
|
|
||
| /** | ||
| * For the given resources, update the primary identifiers of these resources | ||
| */ | ||
| export function importCfnPrimaryIdentifierOverrides(db: SpecDatabase, allowList: CfnPrimaryIdentifierOverrides) { | ||
| const errors = new Array<string>(); | ||
|
|
||
| for (const [resourceType, propNames] of Object.entries(allowList)) { | ||
| try { | ||
| const resource = db.lookup('resource', 'cloudFormationType', 'equals', resourceType).only(); | ||
|
|
||
| for (const propName of propNames) { | ||
| if (!resource.attributes[propName] && !resource.properties[propName]) { | ||
| errors.push(`No such property in CFN Primary Identifiers Override file: ${resourceType}.${propName}`); | ||
| } | ||
|
|
||
| resource.cfnRefIdentifier = propNames; | ||
| } | ||
| } catch (e: any) { | ||
| errors.push(e.message); | ||
| } | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| throw new Error(errors.join('\n')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ages/@aws-cdk/service-spec-importers/src/loaders/load-cfn-primary-identifier-overrides.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { assertSuccess } from '@cdklabs/tskb'; | ||
| import { Loader, LoadResult, LoadSourceOptions } from './loader'; | ||
| import { CfnPrimaryIdentifierOverrides } from '../types'; | ||
|
|
||
| export async function loadCfnPrimaryIdentifierOverrides( | ||
| filePath: string, | ||
| options: LoadSourceOptions = {}, | ||
| ): Promise<LoadResult<CfnPrimaryIdentifierOverrides>> { | ||
| const loader = await Loader.fromSchemaFile<CfnPrimaryIdentifierOverrides>( | ||
| 'CfnPrimaryIdentifierOverrides.schema.json', | ||
| { | ||
| mustValidate: options.validate, | ||
| }, | ||
| ); | ||
|
|
||
| const result = await loader.loadFile(filePath); | ||
| assertSuccess(result); | ||
| return result; | ||
| } |
6 changes: 6 additions & 0 deletions
6
...ec-importers/src/types/cfn-primaryidentifier-overrides/cfn-primaryidentifier-overrides.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Maps a resource type to a list of properties that are also attributes | ||
| */ | ||
| export interface GetAttAllowList { | ||
| [resourceType: string]: string[]; | ||
| } |
4 changes: 2 additions & 2 deletions
4
packages/@aws-cdk/service-spec-importers/src/types/getatt-allowlist/getatt-allowlist.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /** | ||
| * Maps a resource type to a list of properties that are also attributes | ||
| * Maps a resource type to a list of properties that are overrides of the CCAPI schema primary identifiers | ||
| */ | ||
| export interface GetAttAllowList { | ||
| export interface CfnPrimaryIdentifierOverrides { | ||
| [resourceType: string]: string[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/@aws-cdk/service-spec-importers/test/import-cfn-identifiers.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { emptyDatabase, Resource } from '@aws-cdk/service-spec-types'; | ||
| import { importCfnPrimaryIdentifierOverrides } from '../src/importers/import-cfn-primaryidentifier-overrides'; | ||
|
|
||
| let db: ReturnType<typeof emptyDatabase>; | ||
| beforeEach(() => { | ||
| db = emptyDatabase(); | ||
| }); | ||
|
|
||
| test('exercise the CFN identifier import flow', () => { | ||
| db.allocate('resource', { | ||
| cloudFormationType: 'AWS::S3::Bucket', | ||
| attributes: {}, | ||
| name: 'Type', | ||
| primaryIdentifier: ['BucketName'], | ||
| properties: { | ||
| MyProp: { type: { type: 'string' } }, | ||
| }, | ||
| }); | ||
|
|
||
| const overridesDocument = { | ||
| 'AWS::S3::Bucket': ['MyProp'], | ||
| }; | ||
|
|
||
| importCfnPrimaryIdentifierOverrides(db, overridesDocument); | ||
|
|
||
| const res = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::S3::Bucket').only(); | ||
|
|
||
| expect(res).toMatchObject({ | ||
| cfnRefIdentifier: ['MyProp'], | ||
| } satisfies Partial<Resource>); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Summary | ||
|
|
||
| This directory contains overrides for what the `{ Ref }` function returns in CloudFormation, if that disagrees | ||
| with the primary identifier from the schema. | ||
|
|
||
| The schema describes the behavior of CloudControl API, which is the same as the | ||
| behavior of CloudFormation, except when it isn't. | ||
|
|
||
| These are all validated by hand because there is no other automated source of truth for this information. | ||
|
|
||
| # Motivation | ||
|
|
||
| Since CDK is primarily built on top of CloudFormation, we need to know what CloudFormation actually does. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are removing this because we were not using it in the first place right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes