Skip to content

Commit 7d52491

Browse files
authored
feat(cf.findInMap): Default Value Support For Fn::FindInMap (#156)
* Accept default value for Fn::FindInMap * Support default value for Fn::FindInMap * Update Changelog, prerelease * 8.3.0
1 parent ead2650 commit 7d52491

16 files changed

+71
-40
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 8.3.0
4+
5+
- Support a default value for cf.findInMap (Fn::FindInMap).
6+
37
## 8.2.0
48

59
- Add `LogRetentionInDays` option to Lambda shortcuts

lib/intrinsic.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ intrinsic.cidr = (ipBlock, count, cidrBits) => {
4848
* key-value pairs.
4949
* @param {string} attr - The second-level key name, which is set to one of the
5050
* keys from the list assigned to key.
51+
* @param {string} defaultValue - The value that will resolve to if the key and/or attr can not be found from the mapping map.
52+
* This field is optional and requires AWS::LanguageExtensions to be defined in the template.
5153
* @returns The value that is assigned to SecondLevelKey.
5254
*/
53-
intrinsic.findInMap = (mapping, key, attr) => {
54-
return { 'Fn::FindInMap': [mapping, key, attr] };
55+
intrinsic.findInMap = (mapping, key, attr, defaultValue) => {
56+
const lookup = [mapping, key, attr];
57+
if (defaultValue) {
58+
lookup.push({ DefaultValue: defaultValue });
59+
}
60+
return { 'Fn::FindInMap': lookup };
5561
};
5662

5763
/**

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mapbox/cloudfriend",
3-
"version": "8.2.0",
3+
"version": "8.3.0",
44
"description": "Helper functions for assembling CloudFormation templates in JavaScript",
55
"main": "index.js",
66
"engines": {
@@ -11,6 +11,7 @@
1111
"lint": "eslint index.js test lib bin cloudformation",
1212
"lint:fix": "npm run lint -- --fix",
1313
"test": "nyc tape test/*.test.js | tap-spec",
14+
"test:update": "UPDATE=1 npm run test",
1415
"coverage": "nyc --reporter html tape test/*.test.js && opener coverage/index.html",
1516
"build-ci-template": "bin/build-template.js cloudformation/ci.template.js > cloudformation/ci.template.json",
1617
"shortcuts-api-doc": "jsdoc2md lib/shortcuts/*.js > lib/shortcuts/api.md"

test/fixtures/shortcuts/hookshot-github-secret-ref.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"Type": "AWS::ApiGateway::Stage",
2929
"Properties": {
3030
"DeploymentId": {
31-
"Ref": "PassDeploymentac7cb6b9"
31+
"Ref": "PassDeployment2a35d33e"
3232
},
3333
"StageName": "hookshot",
3434
"RestApiId": {
@@ -47,7 +47,7 @@
4747
]
4848
}
4949
},
50-
"PassDeploymentac7cb6b9": {
50+
"PassDeployment2a35d33e": {
5151
"Type": "AWS::ApiGateway::Deployment",
5252
"DependsOn": "PassMethod",
5353
"Properties": {

test/fixtures/shortcuts/hookshot-github-secret-string.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Type": "AWS::ApiGateway::Stage",
2525
"Properties": {
2626
"DeploymentId": {
27-
"Ref": "PassDeploymentac7cb6b9"
27+
"Ref": "PassDeployment2a35d33e"
2828
},
2929
"StageName": "hookshot",
3030
"RestApiId": {
@@ -43,7 +43,7 @@
4343
]
4444
}
4545
},
46-
"PassDeploymentac7cb6b9": {
46+
"PassDeployment2a35d33e": {
4747
"Type": "AWS::ApiGateway::Deployment",
4848
"DependsOn": "PassMethod",
4949
"Properties": {

test/fixtures/shortcuts/hookshot-github.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Type": "AWS::ApiGateway::Stage",
2525
"Properties": {
2626
"DeploymentId": {
27-
"Ref": "PassDeploymentac7cb6b9"
27+
"Ref": "PassDeployment2a35d33e"
2828
},
2929
"StageName": "hookshot",
3030
"RestApiId": {
@@ -43,7 +43,7 @@
4343
]
4444
}
4545
},
46-
"PassDeploymentac7cb6b9": {
46+
"PassDeployment2a35d33e": {
4747
"Type": "AWS::ApiGateway::Deployment",
4848
"DependsOn": "PassMethod",
4949
"Properties": {

test/fixtures/shortcuts/hookshot-passthrough-access-log-format.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Type": "AWS::ApiGateway::Stage",
2525
"Properties": {
2626
"DeploymentId": {
27-
"Ref": "PassDeploymentac7cb6b9"
27+
"Ref": "PassDeployment2a35d33e"
2828
},
2929
"StageName": "hookshot",
3030
"RestApiId": {
@@ -52,7 +52,7 @@
5252
}
5353
}
5454
},
55-
"PassDeploymentac7cb6b9": {
55+
"PassDeployment2a35d33e": {
5656
"Type": "AWS::ApiGateway::Deployment",
5757
"DependsOn": "PassMethod",
5858
"Properties": {

test/fixtures/shortcuts/hookshot-passthrough-alarms.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Type": "AWS::ApiGateway::Stage",
2525
"Properties": {
2626
"DeploymentId": {
27-
"Ref": "PassDeploymentac7cb6b9"
27+
"Ref": "PassDeployment2a35d33e"
2828
},
2929
"StageName": "hookshot",
3030
"RestApiId": {
@@ -43,7 +43,7 @@
4343
]
4444
}
4545
},
46-
"PassDeploymentac7cb6b9": {
46+
"PassDeployment2a35d33e": {
4747
"Type": "AWS::ApiGateway::Deployment",
4848
"DependsOn": "PassMethod",
4949
"Properties": {

test/fixtures/shortcuts/hookshot-passthrough-enhanced-logging.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Type": "AWS::ApiGateway::Stage",
2525
"Properties": {
2626
"DeploymentId": {
27-
"Ref": "PassDeploymentac7cb6b9"
27+
"Ref": "PassDeployment2a35d33e"
2828
},
2929
"StageName": "hookshot",
3030
"RestApiId": {
@@ -43,7 +43,7 @@
4343
]
4444
}
4545
},
46-
"PassDeploymentac7cb6b9": {
46+
"PassDeployment2a35d33e": {
4747
"Type": "AWS::ApiGateway::Deployment",
4848
"DependsOn": "PassMethod",
4949
"Properties": {

0 commit comments

Comments
 (0)