Skip to content

Commit 953de5a

Browse files
committed
Remove exports that aren't necessary at the construct level
1 parent 3968dcf commit 953de5a

2 files changed

Lines changed: 13 additions & 53 deletions

File tree

packages/cdkConstructs/src/constructs/SsmParametersConstruct.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {CfnOutput} from "aws-cdk-lib"
21
import {Effect, ManagedPolicy, PolicyStatement} from "aws-cdk-lib/aws-iam"
32
import {StringParameter} from "aws-cdk-lib/aws-ssm"
43
import {Construct} from "constructs"
@@ -107,9 +106,7 @@ export class SsmParametersConstruct extends Construct {
107106
const {
108107
namePrefix,
109108
parameters,
110-
readPolicyExportSuffix,
111-
readPolicyDescription = "Allows reading SSM parameters",
112-
readPolicyOutputDescription = "Access to the parameters used by the integration"
109+
readPolicyDescription = "Allows reading SSM parameters"
113110
} = props
114111

115112
if (parameters.length === 0) {
@@ -141,12 +138,6 @@ export class SsmParametersConstruct extends Construct {
141138
})
142139

143140
createdParameters[parameter.id] = ssmParameter
144-
145-
new CfnOutput(this, `${parameter.id}ParameterNameOutput`, {
146-
description: parameter.outputDescription ?? parameter.description,
147-
value: ssmParameter.parameterName,
148-
exportName: `${namePrefix}-${parameter.outputExportSuffix ?? parameter.nameSuffix}`
149-
})
150141
}
151142

152143
const readParametersPolicy = new ManagedPolicy(this, "GetParametersPolicy", {
@@ -160,12 +151,6 @@ export class SsmParametersConstruct extends Construct {
160151
]
161152
})
162153

163-
new CfnOutput(this, "ReadParametersPolicyOutput", {
164-
description: readPolicyOutputDescription,
165-
value: readParametersPolicy.managedPolicyArn,
166-
exportName: `${namePrefix}-${readPolicyExportSuffix}`
167-
})
168-
169154
this.parameters = createdParameters
170155
this.readParametersPolicy = readParametersPolicy
171156
}

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

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,10 @@ describe("SsmParametersConstruct", () => {
9999
expect(statement.Action).toEqual(["ssm:GetParameter", "ssm:GetParameters"])
100100
expect(statement.Resource).toHaveLength(3)
101101
})
102-
103-
test("exports parameter names and policy ARN", () => {
104-
const outputs = template.toJSON().Outputs as Record<string, {
105-
Description?: string
106-
Export?: {
107-
Name?: string
108-
}
109-
}>
110-
111-
const exportedNames = Object.values(outputs)
112-
.map((output) => output.Export?.Name)
113-
.filter((name): name is string => name !== undefined)
114-
115-
const descriptions = Object.values(outputs)
116-
.map((output) => output.Description)
117-
.filter((description): description is string => description !== undefined)
118-
119-
expect(exportedNames).toContain("mock-stack-MockParam1Parameter")
120-
expect(exportedNames).toContain("mock-stack-MockParam2Parameter")
121-
expect(exportedNames).toContain("mock-stack-MockParam3Parameter")
122-
expect(exportedNames).toContain("mock-stack-MockGetParametersPolicy")
123-
124-
expect(descriptions).toContain("Name of the SSM parameter holding MockParam1")
125-
expect(descriptions).toContain("Name of the SSM parameter holding MockParam2")
126-
expect(descriptions).toContain("Name of the SSM parameter holding MockParam3")
127-
expect(descriptions).toContain("Mock read policy output description")
128-
})
129102
})
130103

131104
describe("SsmParametersConstruct uses defaults when optional fields are omitted", () => {
132-
test("outputDescription defaults to description and outputExportSuffix defaults to nameSuffix", () => {
105+
test("creates parameter and policy with default readPolicyDescription when optional fields are omitted", () => {
133106
const app = new App()
134107
const stack = new Stack(app, "defaultsStack")
135108
const params = new SsmParametersConstruct(stack, "DefaultsParameters", {
@@ -140,22 +113,24 @@ describe("SsmParametersConstruct uses defaults when optional fields are omitted"
140113
nameSuffix: "MockParam1Suffix",
141114
description: "Mock SSM parameter description",
142115
value: "mock-value-1"
143-
// outputDescription and outputExportSuffix intentionally omitted
144116
}
145-
]
117+
],
118+
readPolicyExportSuffix: "MockGetParametersPolicy"
146119
})
147120
// Get sonar to shup up about the construct not being used
148121
assert(params, "SsmParametersConstruct should be created successfully")
149122
const template = Template.fromStack(stack)
150123

151-
const outputs = template.toJSON().Outputs as Record<string, {
152-
Description?: string
153-
Export?: {Name?: string}
154-
}>
124+
template.hasResourceProperties("AWS::SSM::Parameter", {
125+
Name: "mock-stack-MockParam1Suffix",
126+
Type: "String",
127+
Value: "mock-value-1",
128+
Description: "Mock SSM parameter description"
129+
})
155130

156-
const outputValues = Object.values(outputs)
157-
expect(outputValues.some((o) => o.Description === "Mock SSM parameter description")).toBe(true)
158-
expect(outputValues.some((o) => o.Export?.Name === "mock-stack-MockParam1Suffix")).toBe(true)
131+
template.hasResourceProperties("AWS::IAM::ManagedPolicy", {
132+
Description: "Allows reading SSM parameters"
133+
})
159134
})
160135
})
161136

0 commit comments

Comments
 (0)