Skip to content

Commit 8526feb

Browse files
authored
feat(core): Fn.findInMap supports default value (#26543)
Cloudformation recently [added support](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap-enhancements.html) for a default value in the FindInMap intrinsic function. This adds that support. Closes #26125. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 112b861 commit 8526feb

13 files changed

+840
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "32.0.0",
3+
"files": {
4+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Parameters": {
3+
"BootstrapVersion": {
4+
"Type": "AWS::SSM::Parameter::Value<String>",
5+
"Default": "/cdk-bootstrap/hnb659fds/version",
6+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
7+
}
8+
},
9+
"Rules": {
10+
"CheckBootstrapVersion": {
11+
"Assertions": [
12+
{
13+
"Assert": {
14+
"Fn::Not": [
15+
{
16+
"Fn::Contains": [
17+
[
18+
"1",
19+
"2",
20+
"3",
21+
"4",
22+
"5"
23+
],
24+
{
25+
"Ref": "BootstrapVersion"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"32.0.0"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "32.0.0",
3+
"files": {
4+
"175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5": {
5+
"source": {
6+
"path": "core-cfn-mapping-1.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"Transform": [
3+
"AWS::LanguageExtensions"
4+
],
5+
"Mappings": {
6+
"Regularmapping": {
7+
"TopLevelKey1": {
8+
"SecondLevelKey1": "Yes",
9+
"SecondLevelKey2": "No"
10+
}
11+
},
12+
"Lazymapping": {
13+
"TopLevelKey1": {
14+
"SecondLevelKey1": "Yes",
15+
"SecondLevelKey2": "No"
16+
}
17+
}
18+
},
19+
"Outputs": {
20+
"Output0": {
21+
"Value": {
22+
"Fn::FindInMap": [
23+
"Regularmapping",
24+
"TopLevelKey1",
25+
"SecondLevelKey1",
26+
{
27+
"DefaultValue": "foob"
28+
}
29+
]
30+
}
31+
},
32+
"Output1": {
33+
"Value": {
34+
"Fn::FindInMap": [
35+
"Regularmapping",
36+
"TopLevelKey1",
37+
{
38+
"Ref": "AWS::Region"
39+
},
40+
{
41+
"DefaultValue": "foob"
42+
}
43+
]
44+
}
45+
},
46+
"Output2": {
47+
"Value": {
48+
"Fn::FindInMap": [
49+
"Regularmapping",
50+
"TopLevelKey1",
51+
"SecondLevelKey3",
52+
{
53+
"DefaultValue": "foob"
54+
}
55+
]
56+
}
57+
},
58+
"Output3": {
59+
"Value": "No"
60+
},
61+
"Output4": {
62+
"Value": "bart"
63+
},
64+
"Output5": {
65+
"Value": {
66+
"Fn::FindInMap": [
67+
"Lazymapping",
68+
{
69+
"Ref": "AWS::Region"
70+
},
71+
"SecondLevelKey2",
72+
{
73+
"DefaultValue": "bart"
74+
}
75+
]
76+
}
77+
}
78+
},
79+
"Resources": {
80+
"CfnMappingFindInMapBucket6F72FEE7": {
81+
"Type": "AWS::S3::Bucket",
82+
"UpdateReplacePolicy": "Retain",
83+
"DeletionPolicy": "Retain"
84+
}
85+
},
86+
"Parameters": {
87+
"BootstrapVersion": {
88+
"Type": "AWS::SSM::Parameter::Value<String>",
89+
"Default": "/cdk-bootstrap/hnb659fds/version",
90+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
91+
}
92+
},
93+
"Rules": {
94+
"CheckBootstrapVersion": {
95+
"Assertions": [
96+
{
97+
"Assert": {
98+
"Fn::Not": [
99+
{
100+
"Fn::Contains": [
101+
[
102+
"1",
103+
"2",
104+
"3",
105+
"4",
106+
"5"
107+
],
108+
{
109+
"Ref": "BootstrapVersion"
110+
}
111+
]
112+
}
113+
]
114+
},
115+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
116+
}
117+
]
118+
}
119+
}
120+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "32.0.0",
3+
"testCases": {
4+
"CfnMappingFindInMapTest/DefaultTest": {
5+
"stacks": [
6+
"core-cfn-mapping-1"
7+
],
8+
"assertionStack": "CfnMappingFindInMapTest/DefaultTest/DeployAssert",
9+
"assertionStackName": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"version": "32.0.0",
3+
"artifacts": {
4+
"core-cfn-mapping-1.assets": {
5+
"type": "cdk:asset-manifest",
6+
"properties": {
7+
"file": "core-cfn-mapping-1.assets.json",
8+
"requiresBootstrapStackVersion": 6,
9+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
10+
}
11+
},
12+
"core-cfn-mapping-1": {
13+
"type": "aws:cloudformation:stack",
14+
"environment": "aws://unknown-account/unknown-region",
15+
"properties": {
16+
"templateFile": "core-cfn-mapping-1.template.json",
17+
"validateOnSynth": false,
18+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
19+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5.json",
21+
"requiresBootstrapStackVersion": 6,
22+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
23+
"additionalDependencies": [
24+
"core-cfn-mapping-1.assets"
25+
],
26+
"lookupRole": {
27+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
28+
"requiresBootstrapStackVersion": 8,
29+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
30+
}
31+
},
32+
"dependencies": [
33+
"core-cfn-mapping-1.assets"
34+
],
35+
"metadata": {
36+
"/core-cfn-mapping-1/Regular mapping": [
37+
{
38+
"type": "aws:cdk:logicalId",
39+
"data": "Regularmapping"
40+
}
41+
],
42+
"/core-cfn-mapping-1/Lazy mapping": [
43+
{
44+
"type": "aws:cdk:logicalId",
45+
"data": "Lazymapping"
46+
}
47+
],
48+
"/core-cfn-mapping-1/Output0": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "Output0"
52+
}
53+
],
54+
"/core-cfn-mapping-1/Output1": [
55+
{
56+
"type": "aws:cdk:logicalId",
57+
"data": "Output1"
58+
}
59+
],
60+
"/core-cfn-mapping-1/Output2": [
61+
{
62+
"type": "aws:cdk:logicalId",
63+
"data": "Output2"
64+
}
65+
],
66+
"/core-cfn-mapping-1/Output3": [
67+
{
68+
"type": "aws:cdk:logicalId",
69+
"data": "Output3"
70+
}
71+
],
72+
"/core-cfn-mapping-1/Output4": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "Output4"
76+
}
77+
],
78+
"/core-cfn-mapping-1/Output5": [
79+
{
80+
"type": "aws:cdk:logicalId",
81+
"data": "Output5"
82+
}
83+
],
84+
"/core-cfn-mapping-1/CfnMappingFindInMapBucket/Resource": [
85+
{
86+
"type": "aws:cdk:logicalId",
87+
"data": "CfnMappingFindInMapBucket6F72FEE7"
88+
}
89+
],
90+
"/core-cfn-mapping-1/BootstrapVersion": [
91+
{
92+
"type": "aws:cdk:logicalId",
93+
"data": "BootstrapVersion"
94+
}
95+
],
96+
"/core-cfn-mapping-1/CheckBootstrapVersion": [
97+
{
98+
"type": "aws:cdk:logicalId",
99+
"data": "CheckBootstrapVersion"
100+
}
101+
]
102+
},
103+
"displayName": "core-cfn-mapping-1"
104+
},
105+
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets": {
106+
"type": "cdk:asset-manifest",
107+
"properties": {
108+
"file": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets.json",
109+
"requiresBootstrapStackVersion": 6,
110+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
111+
}
112+
},
113+
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D": {
114+
"type": "aws:cloudformation:stack",
115+
"environment": "aws://unknown-account/unknown-region",
116+
"properties": {
117+
"templateFile": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.template.json",
118+
"validateOnSynth": false,
119+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
120+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
121+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
122+
"requiresBootstrapStackVersion": 6,
123+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
124+
"additionalDependencies": [
125+
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets"
126+
],
127+
"lookupRole": {
128+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
129+
"requiresBootstrapStackVersion": 8,
130+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
131+
}
132+
},
133+
"dependencies": [
134+
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets"
135+
],
136+
"metadata": {
137+
"/CfnMappingFindInMapTest/DefaultTest/DeployAssert/BootstrapVersion": [
138+
{
139+
"type": "aws:cdk:logicalId",
140+
"data": "BootstrapVersion"
141+
}
142+
],
143+
"/CfnMappingFindInMapTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [
144+
{
145+
"type": "aws:cdk:logicalId",
146+
"data": "CheckBootstrapVersion"
147+
}
148+
]
149+
},
150+
"displayName": "CfnMappingFindInMapTest/DefaultTest/DeployAssert"
151+
},
152+
"Tree": {
153+
"type": "cdk:tree",
154+
"properties": {
155+
"file": "tree.json"
156+
}
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)