Skip to content

Commit

Permalink
feat(core): Fn.findInMap supports default value (#26543)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
scanlonp authored Aug 8, 2023
1 parent 112b861 commit 8526feb
Show file tree
Hide file tree
Showing 13 changed files with 840 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "32.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "32.0.0",
"files": {
"175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5": {
"source": {
"path": "core-cfn-mapping-1.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"Transform": [
"AWS::LanguageExtensions"
],
"Mappings": {
"Regularmapping": {
"TopLevelKey1": {
"SecondLevelKey1": "Yes",
"SecondLevelKey2": "No"
}
},
"Lazymapping": {
"TopLevelKey1": {
"SecondLevelKey1": "Yes",
"SecondLevelKey2": "No"
}
}
},
"Outputs": {
"Output0": {
"Value": {
"Fn::FindInMap": [
"Regularmapping",
"TopLevelKey1",
"SecondLevelKey1",
{
"DefaultValue": "foob"
}
]
}
},
"Output1": {
"Value": {
"Fn::FindInMap": [
"Regularmapping",
"TopLevelKey1",
{
"Ref": "AWS::Region"
},
{
"DefaultValue": "foob"
}
]
}
},
"Output2": {
"Value": {
"Fn::FindInMap": [
"Regularmapping",
"TopLevelKey1",
"SecondLevelKey3",
{
"DefaultValue": "foob"
}
]
}
},
"Output3": {
"Value": "No"
},
"Output4": {
"Value": "bart"
},
"Output5": {
"Value": {
"Fn::FindInMap": [
"Lazymapping",
{
"Ref": "AWS::Region"
},
"SecondLevelKey2",
{
"DefaultValue": "bart"
}
]
}
}
},
"Resources": {
"CfnMappingFindInMapBucket6F72FEE7": {
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "32.0.0",
"testCases": {
"CfnMappingFindInMapTest/DefaultTest": {
"stacks": [
"core-cfn-mapping-1"
],
"assertionStack": "CfnMappingFindInMapTest/DefaultTest/DeployAssert",
"assertionStackName": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"version": "32.0.0",
"artifacts": {
"core-cfn-mapping-1.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "core-cfn-mapping-1.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"core-cfn-mapping-1": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "core-cfn-mapping-1.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/175902e9c94a814a5739a092426ef29b46a5098db6118c5c464b507fa4e867e5.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"core-cfn-mapping-1.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"core-cfn-mapping-1.assets"
],
"metadata": {
"/core-cfn-mapping-1/Regular mapping": [
{
"type": "aws:cdk:logicalId",
"data": "Regularmapping"
}
],
"/core-cfn-mapping-1/Lazy mapping": [
{
"type": "aws:cdk:logicalId",
"data": "Lazymapping"
}
],
"/core-cfn-mapping-1/Output0": [
{
"type": "aws:cdk:logicalId",
"data": "Output0"
}
],
"/core-cfn-mapping-1/Output1": [
{
"type": "aws:cdk:logicalId",
"data": "Output1"
}
],
"/core-cfn-mapping-1/Output2": [
{
"type": "aws:cdk:logicalId",
"data": "Output2"
}
],
"/core-cfn-mapping-1/Output3": [
{
"type": "aws:cdk:logicalId",
"data": "Output3"
}
],
"/core-cfn-mapping-1/Output4": [
{
"type": "aws:cdk:logicalId",
"data": "Output4"
}
],
"/core-cfn-mapping-1/Output5": [
{
"type": "aws:cdk:logicalId",
"data": "Output5"
}
],
"/core-cfn-mapping-1/CfnMappingFindInMapBucket/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "CfnMappingFindInMapBucket6F72FEE7"
}
],
"/core-cfn-mapping-1/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/core-cfn-mapping-1/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "core-cfn-mapping-1"
},
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"CfnMappingFindInMapTestDefaultTestDeployAssertEA32B10D.assets"
],
"metadata": {
"/CfnMappingFindInMapTest/DefaultTest/DeployAssert/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/CfnMappingFindInMapTest/DefaultTest/DeployAssert/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "CfnMappingFindInMapTest/DefaultTest/DeployAssert"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading

0 comments on commit 8526feb

Please sign in to comment.