Skip to content
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

fix(core): the string 'undefined' is recognized as a valid partition when looking up for fact values #23023

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/@aws-cdk/core/lib/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,10 @@ export class Stack extends Construct implements ITaggable {
throw new Error(`Context value '${cxapi.TARGET_PARTITIONS}' should be a list of strings, got: ${JSON.stringify(partitions)}`);
}

const lookupMap = partitions ? RegionInfo.limitedRegionMap(factName, partitions) : RegionInfo.regionMap(factName);
const lookupMap =
partitions !== undefined && partitions !== 'undefined'
? RegionInfo.limitedRegionMap(factName, partitions)
: RegionInfo.regionMap(factName);

return deployTimeLookup(this, factName, lookupMap, defaultValue);
}
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/core/test/stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,31 @@ describe('regionalFact', () => {
expect(stack.regionalFact('MyFact')).toEqual('x.amazonaws.com');
});

test('regional facts use the global lookup map if partition is the literal string of "undefined"', () => {
const stack = new Stack();
Node.of(stack).setContext(cxapi.TARGET_PARTITIONS, 'undefined');
new CfnOutput(stack, 'TheFact', {
value: stack.regionalFact('WeirdFact'),
});

expect(toCloudFormation(stack)).toEqual({
Mappings: {
WeirdFactMap: {
'eu-west-1': { value: 'otherformat' },
'us-east-1': { value: 'oneformat' },
},
},
Outputs: {
TheFact: {
Value: {
'Fn::FindInMap': ['WeirdFactMap', { Ref: 'AWS::Region' }, 'value'],
},
},
},
});

});

test('regional facts generate a mapping if necessary', () => {
const stack = new Stack();
new CfnOutput(stack, 'TheFact', {
Expand Down