Skip to content

Commit 1f1b642

Browse files
authored
fix(ssm): cannot import a ssm parameter with a name containing unresolved token (#25749)
Previously, when we import a SSM parameter by `ssm.StringParameter.fromStringParameterAttributes`, we use `CfnParameter` to get the value. ```json "Parameters": { "importsqsstringparamParameter": { "Type": "AWS::SSM::Parameter::Value<String>", "Default": { "Fn::ImportValue": "some-exported-value-holding-the-param-name" } }, ``` However, `Parameters.<Name>.Default` only allows a concrete string value. If it contains e.g. intrinsic functions, we get an error like this from CFn: `Template format error: Every Default member must be a string.` This PR changes the behavior of `fromStringParameterAttributes` method. Now it uses `CfnDynamicReference` instead of `CfnParameter` if a parameter name contains unresolved tokens. Since previously the case when `Token.isUnresolved(attrs.parameterName) == true` just resulted in a deployment error, this is not a breaking change. Closes #17094 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9065b25 commit 1f1b642

12 files changed

+642
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "32.0.0",
3+
"files": {
4+
"0c9f637062451a2002409e9c30b657f39990631000a05a12bef7fcdb73ec5332": {
5+
"source": {
6+
"path": "Import-SSM-Parameter.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "0c9f637062451a2002409e9c30b657f39990631000a05a12bef7fcdb73ec5332.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,85 @@
1+
{
2+
"Resources": {
3+
"StringParameter472EED0E": {
4+
"Type": "AWS::SSM::Parameter",
5+
"Properties": {
6+
"Type": "String",
7+
"Value": "Initial parameter value",
8+
"Name": "import-parameter-test"
9+
}
10+
}
11+
},
12+
"Parameters": {
13+
"ImportedWithNameParameter": {
14+
"Type": "AWS::SSM::Parameter::Value<String>",
15+
"Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs"
16+
},
17+
"BootstrapVersion": {
18+
"Type": "AWS::SSM::Parameter::Value<String>",
19+
"Default": "/cdk-bootstrap/hnb659fds/version",
20+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
21+
}
22+
},
23+
"Outputs": {
24+
"ImportedWithNameOutput": {
25+
"Value": {
26+
"Ref": "ImportedWithNameParameter"
27+
}
28+
},
29+
"ImportedWithIntrinsicOutput": {
30+
"Value": {
31+
"Fn::Join": [
32+
"",
33+
[
34+
"{{resolve:ssm:",
35+
{
36+
"Ref": "StringParameter472EED0E"
37+
},
38+
"}}"
39+
]
40+
]
41+
}
42+
},
43+
"ImportedWithForceFlagOutput": {
44+
"Value": {
45+
"Fn::Join": [
46+
"",
47+
[
48+
"{{resolve:ssm:",
49+
{
50+
"Ref": "StringParameter472EED0E"
51+
},
52+
"}}"
53+
]
54+
]
55+
}
56+
}
57+
},
58+
"Rules": {
59+
"CheckBootstrapVersion": {
60+
"Assertions": [
61+
{
62+
"Assert": {
63+
"Fn::Not": [
64+
{
65+
"Fn::Contains": [
66+
[
67+
"1",
68+
"2",
69+
"3",
70+
"4",
71+
"5"
72+
],
73+
{
74+
"Ref": "BootstrapVersion"
75+
}
76+
]
77+
}
78+
]
79+
},
80+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
81+
}
82+
]
83+
}
84+
}
85+
}
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+
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
5+
"source": {
6+
"path": "cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.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,12 @@
1+
{
2+
"version": "32.0.0",
3+
"testCases": {
4+
"cdk-integ-import-ssm-parameter/DefaultTest": {
5+
"stacks": [
6+
"Import-SSM-Parameter"
7+
],
8+
"assertionStack": "cdk-integ-import-ssm-parameter/DefaultTest/DeployAssert",
9+
"assertionStackName": "cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843"
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"version": "32.0.0",
3+
"artifacts": {
4+
"Import-SSM-Parameter.assets": {
5+
"type": "cdk:asset-manifest",
6+
"properties": {
7+
"file": "Import-SSM-Parameter.assets.json",
8+
"requiresBootstrapStackVersion": 6,
9+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
10+
}
11+
},
12+
"Import-SSM-Parameter": {
13+
"type": "aws:cloudformation:stack",
14+
"environment": "aws://unknown-account/unknown-region",
15+
"properties": {
16+
"templateFile": "Import-SSM-Parameter.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}/0c9f637062451a2002409e9c30b657f39990631000a05a12bef7fcdb73ec5332.json",
21+
"requiresBootstrapStackVersion": 6,
22+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
23+
"additionalDependencies": [
24+
"Import-SSM-Parameter.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+
"Import-SSM-Parameter.assets"
34+
],
35+
"metadata": {
36+
"/Import-SSM-Parameter/StringParameter/Resource": [
37+
{
38+
"type": "aws:cdk:logicalId",
39+
"data": "StringParameter472EED0E"
40+
}
41+
],
42+
"/Import-SSM-Parameter/ImportedWithName.Parameter": [
43+
{
44+
"type": "aws:cdk:logicalId",
45+
"data": "ImportedWithNameParameter"
46+
}
47+
],
48+
"/Import-SSM-Parameter/ImportedWithNameOutput": [
49+
{
50+
"type": "aws:cdk:logicalId",
51+
"data": "ImportedWithNameOutput"
52+
}
53+
],
54+
"/Import-SSM-Parameter/ImportedWithIntrinsicOutput": [
55+
{
56+
"type": "aws:cdk:logicalId",
57+
"data": "ImportedWithIntrinsicOutput"
58+
}
59+
],
60+
"/Import-SSM-Parameter/ImportedWithForceFlagOutput": [
61+
{
62+
"type": "aws:cdk:logicalId",
63+
"data": "ImportedWithForceFlagOutput"
64+
}
65+
],
66+
"/Import-SSM-Parameter/BootstrapVersion": [
67+
{
68+
"type": "aws:cdk:logicalId",
69+
"data": "BootstrapVersion"
70+
}
71+
],
72+
"/Import-SSM-Parameter/CheckBootstrapVersion": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "CheckBootstrapVersion"
76+
}
77+
]
78+
},
79+
"displayName": "Import-SSM-Parameter"
80+
},
81+
"cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.assets": {
82+
"type": "cdk:asset-manifest",
83+
"properties": {
84+
"file": "cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.assets.json",
85+
"requiresBootstrapStackVersion": 6,
86+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
87+
}
88+
},
89+
"cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843": {
90+
"type": "aws:cloudformation:stack",
91+
"environment": "aws://unknown-account/unknown-region",
92+
"properties": {
93+
"templateFile": "cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.template.json",
94+
"validateOnSynth": false,
95+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
96+
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
97+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
98+
"requiresBootstrapStackVersion": 6,
99+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
100+
"additionalDependencies": [
101+
"cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.assets"
102+
],
103+
"lookupRole": {
104+
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
105+
"requiresBootstrapStackVersion": 8,
106+
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
107+
}
108+
},
109+
"dependencies": [
110+
"cdkintegimportssmparameterDefaultTestDeployAssert2A3D6843.assets"
111+
],
112+
"metadata": {
113+
"/cdk-integ-import-ssm-parameter/DefaultTest/DeployAssert/BootstrapVersion": [
114+
{
115+
"type": "aws:cdk:logicalId",
116+
"data": "BootstrapVersion"
117+
}
118+
],
119+
"/cdk-integ-import-ssm-parameter/DefaultTest/DeployAssert/CheckBootstrapVersion": [
120+
{
121+
"type": "aws:cdk:logicalId",
122+
"data": "CheckBootstrapVersion"
123+
}
124+
]
125+
},
126+
"displayName": "cdk-integ-import-ssm-parameter/DefaultTest/DeployAssert"
127+
},
128+
"Tree": {
129+
"type": "cdk:tree",
130+
"properties": {
131+
"file": "tree.json"
132+
}
133+
}
134+
}
135+
}

0 commit comments

Comments
 (0)