Skip to content

Commit 2afccf1

Browse files
committed
Fallback to non optional descriptions and names
1 parent f7e421d commit 2afccf1

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

packages/cdkConstructs/src/constructs/SsmParametersConstruct.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ export interface SsmParameterDefinition {
2323
readonly value: string
2424
/**
2525
* Optional export suffix for the output containing the parameter name.
26-
* Defaults to `${nameSuffix}Parameter`.
26+
* Defaults to `nameSuffix`.
2727
*/
2828
readonly outputExportSuffix?: string
2929
/**
3030
* Optional output description.
31+
* Defaults to `description`.
3132
*/
3233
readonly outputDescription?: string
3334
}
@@ -108,9 +109,9 @@ export class SsmParametersConstruct extends Construct {
108109
createdParameters[parameter.id] = ssmParameter
109110

110111
new CfnOutput(this, `${parameter.id}ParameterNameOutput`, {
111-
description: parameter.outputDescription ?? `Name of the SSM parameter holding ${parameter.nameSuffix}`,
112+
description: parameter.outputDescription ?? parameter.description,
112113
value: ssmParameter.parameterName,
113-
exportName: `${stackName}-${parameter.outputExportSuffix ?? `${parameter.nameSuffix}Parameter`}`
114+
exportName: `${stackName}-${parameter.outputExportSuffix ?? parameter.nameSuffix}`
114115
})
115116
}
116117

packages/cdkConstructs/tests/constructs/ssmParametersConstruct.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ describe("SsmParametersConstruct", () => {
128128
})
129129
})
130130

131+
describe("SsmParametersConstruct uses defaults when optional fields are omitted", () => {
132+
test("outputDescription defaults to description and outputExportSuffix defaults to nameSuffix", () => {
133+
const app = new App()
134+
const stack = new Stack(app, "defaultsStack")
135+
new SsmParametersConstruct(stack, "DefaultsParameters", {
136+
namePrefix: "mock-stack",
137+
parameters: [
138+
{
139+
id: "MockParam1",
140+
nameSuffix: "MockParam1Suffix",
141+
description: "Mock SSM parameter description",
142+
value: "mock-value-1"
143+
// outputDescription and outputExportSuffix intentionally omitted
144+
}
145+
]
146+
})
147+
const template = Template.fromStack(stack)
148+
149+
const outputs = template.toJSON().Outputs as Record<string, {
150+
Description?: string
151+
Export?: {Name?: string}
152+
}>
153+
154+
const outputValues = Object.values(outputs)
155+
expect(outputValues.some((o) => o.Description === "Mock SSM parameter description")).toBe(true)
156+
expect(outputValues.some((o) => o.Export?.Name === "mock-stack-MockParam1Suffix")).toBe(true)
157+
})
158+
})
159+
131160
describe("SsmParametersConstruct validation", () => {
132161
test("throws when parameters array is empty", () => {
133162
const app = new App()

0 commit comments

Comments
 (0)