Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssm): StringParameter.fromSecureStringParameterAttributes not working without version #22311

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-ssm/lib/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ export class StringParameter extends ParameterBase implements IStringParameter {
*/
public static fromSecureStringParameterAttributes(scope: Construct, id: string, attrs: SecureStringParameterAttributes): IStringParameter {
const version = attrs.version ? Tokenization.stringifyNumber(attrs.version) : '';
const stringValue = new CfnDynamicReference(CfnDynamicReferenceService.SSM_SECURE, `${attrs.parameterName}:${version}`).toString();
const stringValue = new CfnDynamicReference(
CfnDynamicReferenceService.SSM_SECURE,
version ? `${attrs.parameterName}:${version}` : attrs.parameterName,
).toString();

class Import extends ParameterBase {
public readonly parameterName = attrs.parameterName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class UsingStack extends cdk.Stack {
}).stringValue;

// Retrieve a specific version of the secret (SecureString) parameter.
// 'version' is always required.
const secretValue = ssm.StringParameter.fromSecureStringParameterAttributes(this, 'MySecureValue', {
parameterName: '/My/Secret/Parameter',
});
const secretValueVersion = ssm.StringParameter.fromSecureStringParameterAttributes(this, 'MySecureValueVersion', {
parameterName: '/My/Secret/Parameter',
version: 5,
});
const secretValueVersionFromToken = ssm.StringParameter.fromSecureStringParameterAttributes(this, 'MySecureValueVersionFromToken', {
Expand All @@ -57,6 +59,7 @@ class UsingStack extends cdk.Stack {

// Cannot be provisioned so cannot be actually used
Array.isArray(secretValue);
Array.isArray(secretValueVersion);
Array.isArray(secretValueVersionFromToken);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ssm/test/parameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ test('StringParameter.fromSecureStringParameterAttributes without version', () =
});

// THEN
expect(stack.resolve(param.stringValue)).toEqual('{{resolve:ssm-secure:MyParamName:}}');
expect(stack.resolve(param.stringValue)).toEqual('{{resolve:ssm-secure:MyParamName}}');
});

test('StringListParameter.fromName', () => {
Expand Down