Skip to content

Commit 416d544

Browse files
authored
Merge branch 'main' into fix/malformed-arns
2 parents 9690386 + e2deca0 commit 416d544

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

packages/@aws-cdk/core/lib/cfn-resource.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,35 @@ function deepMerge(target: any, ...sources: any[]) {
609609
}
610610
}
611611

612+
/**
613+
* There might also be the case where the source is an intrinsic
614+
*
615+
* target: {
616+
* Type: 'MyResourceType',
617+
* Properties: {
618+
* prop1: { subprop: { name: { 'Fn::GetAtt': 'abc' } } }
619+
* }
620+
* }
621+
* sources: [ {
622+
* Properties: {
623+
* prop1: { subprop: { 'Fn::If': ['SomeCondition', {...}, {...}] }}
624+
* }
625+
* } ]
626+
*
627+
* We end up in a place that is the reverse of the above check, the source
628+
* becomes an intrinsic before the target
629+
*
630+
* target: { subprop: { name: { 'Fn::GetAtt': 'abc' } } }
631+
* sources: [{
632+
* 'Fn::If': [ 'MyCondition', {...}, {...} ]
633+
* }]
634+
*/
635+
if (Object.keys(value).length === 1) {
636+
if (MERGE_EXCLUDE_KEYS.includes(Object.keys(value)[0])) {
637+
target[key] = {};
638+
}
639+
}
640+
612641
deepMerge(target[key], value);
613642

614643
// if the result of the merge is an empty object, it's because the

packages/@aws-cdk/core/test/resource.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,59 @@ describe('resource', () => {
726726
});
727727
});
728728

729+
test('Can override a an object with an intrinsic', () => {
730+
// GIVEN
731+
const stack = new Stack();
732+
733+
const condition = new CfnCondition(stack, 'MyCondition', {
734+
expression: Fn.conditionEquals('us-east-1', 'us-east-1'),
735+
});
736+
const resource = new CfnResource(stack, 'MyResource', {
737+
type: 'MyResourceType',
738+
properties: {
739+
prop1: {
740+
subprop: {
741+
name: Fn.getAtt('resource', 'abc'),
742+
},
743+
},
744+
},
745+
});
746+
const isEnabled = Fn.conditionIf(condition.logicalId, {
747+
Ref: 'AWS::NoValue',
748+
}, {
749+
name: Fn.getAtt('resource', 'abc'),
750+
});
751+
752+
// WHEN
753+
resource.addPropertyOverride('prop1.subprop', isEnabled);
754+
const cfn = toCloudFormation(stack);
755+
756+
// THEN
757+
expect(cfn.Resources.MyResource).toEqual({
758+
Type: 'MyResourceType',
759+
Properties: {
760+
prop1: {
761+
subprop: {
762+
'Fn::If': [
763+
'MyCondition',
764+
{
765+
Ref: 'AWS::NoValue',
766+
},
767+
{
768+
name: {
769+
'Fn::GetAtt': [
770+
'resource',
771+
'abc',
772+
],
773+
},
774+
},
775+
],
776+
},
777+
},
778+
},
779+
});
780+
});
781+
729782
test('overrides allow overriding a nested intrinsic', () => {
730783
// GIVEN
731784
const stack = new Stack();

0 commit comments

Comments
 (0)