Skip to content

Commit d53c451

Browse files
authored
Chore: [AEA-6258] - Remove exports that aren't necessary at the construct level (#647)
## Summary - Routine Change ### Details The export of a parameter is not needed in all cases - it should be handled higher up the hierarchy, rather than doing it by default at the construct level every time.
1 parent 3968dcf commit d53c451

2 files changed

Lines changed: 15 additions & 87 deletions

File tree

packages/cdkConstructs/src/constructs/SsmParametersConstruct.ts

Lines changed: 1 addition & 39 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"
@@ -34,16 +33,6 @@ export interface SsmParameterDefinition {
3433
* Value stored in the SSM parameter.
3534
*/
3635
readonly value: string
37-
/**
38-
* Optional export suffix for the output containing the parameter name.
39-
* @default nameSuffix value
40-
*/
41-
readonly outputExportSuffix?: string
42-
/**
43-
* Optional output description.
44-
* @default description value
45-
*/
46-
readonly outputDescription?: string
4736
}
4837

4938
/**
@@ -54,10 +43,6 @@ export interface SsmParameterDefinition {
5443
* @property parameters List of SSM parameters to create.
5544
* @property readPolicyDescription Description for the managed policy that grants
5645
* read access. Defaults to "Allows reading SSM parameters".
57-
* @property readPolicyOutputDescription Description for the output exporting the
58-
* managed policy ARN. Defaults to "Access to the parameters used by the integration".
59-
* @property readPolicyExportSuffix Export suffix for the output exporting the
60-
* managed policy ARN.
6146
*/
6247
export interface SsmParametersConstructProps {
6348
/**
@@ -73,15 +58,6 @@ export interface SsmParametersConstructProps {
7358
* @default "Allows reading SSM parameters"
7459
*/
7560
readonly readPolicyDescription?: string
76-
/**
77-
* Description for the output exporting the managed policy ARN.
78-
* @default "Access to the parameters used by the integration"
79-
*/
80-
readonly readPolicyOutputDescription?: string
81-
/**
82-
* Export suffix for the output exporting the managed policy ARN.
83-
*/
84-
readonly readPolicyExportSuffix: string
8561
}
8662

8763
/**
@@ -107,9 +83,7 @@ export class SsmParametersConstruct extends Construct {
10783
const {
10884
namePrefix,
10985
parameters,
110-
readPolicyExportSuffix,
111-
readPolicyDescription = "Allows reading SSM parameters",
112-
readPolicyOutputDescription = "Access to the parameters used by the integration"
86+
readPolicyDescription = "Allows reading SSM parameters"
11387
} = props
11488

11589
if (parameters.length === 0) {
@@ -141,12 +115,6 @@ export class SsmParametersConstruct extends Construct {
141115
})
142116

143117
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-
})
150118
}
151119

152120
const readParametersPolicy = new ManagedPolicy(this, "GetParametersPolicy", {
@@ -160,12 +128,6 @@ export class SsmParametersConstruct extends Construct {
160128
]
161129
})
162130

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

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

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,22 @@ describe("SsmParametersConstruct", () => {
2424
id: "MockParam1",
2525
nameSuffix: "MockParam1",
2626
description: "Description for mock parameter 1",
27-
value: "mock-value-1",
28-
outputExportSuffix: "MockParam1Parameter",
29-
outputDescription: "Name of the SSM parameter holding MockParam1"
27+
value: "mock-value-1"
3028
},
3129
{
3230
id: "MockParam2",
3331
nameSuffix: "MockParam2",
3432
description: "Description for mock parameter 2",
35-
value: "mock-value-2",
36-
outputExportSuffix: "MockParam2Parameter",
37-
outputDescription: "Name of the SSM parameter holding MockParam2"
33+
value: "mock-value-2"
3834
},
3935
{
4036
id: "MockParam3",
4137
nameSuffix: "MockParam3",
4238
description: "Description for mock parameter 3",
43-
value: "mock-value-3",
44-
outputExportSuffix: "MockParam3Parameter",
45-
outputDescription: "Name of the SSM parameter holding MockParam3"
39+
value: "mock-value-3"
4640
}
4741
],
48-
readPolicyDescription: "Mock policy description",
49-
readPolicyOutputDescription: "Mock read policy output description",
50-
readPolicyExportSuffix: "MockGetParametersPolicy"
42+
readPolicyDescription: "Mock policy description"
5143
})
5244
// Sonarcloud complains that the construct is not used, so we add an assertion to sidestep that.
5345
assert(params, "SsmParametersConstruct should be created successfully")
@@ -99,37 +91,10 @@ describe("SsmParametersConstruct", () => {
9991
expect(statement.Action).toEqual(["ssm:GetParameter", "ssm:GetParameters"])
10092
expect(statement.Resource).toHaveLength(3)
10193
})
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-
})
12994
})
13095

13196
describe("SsmParametersConstruct uses defaults when optional fields are omitted", () => {
132-
test("outputDescription defaults to description and outputExportSuffix defaults to nameSuffix", () => {
97+
test("creates parameter and policy with default readPolicyDescription", () => {
13398
const app = new App()
13499
const stack = new Stack(app, "defaultsStack")
135100
const params = new SsmParametersConstruct(stack, "DefaultsParameters", {
@@ -140,22 +105,23 @@ describe("SsmParametersConstruct uses defaults when optional fields are omitted"
140105
nameSuffix: "MockParam1Suffix",
141106
description: "Mock SSM parameter description",
142107
value: "mock-value-1"
143-
// outputDescription and outputExportSuffix intentionally omitted
144108
}
145109
]
146110
})
147111
// Get sonar to shup up about the construct not being used
148112
assert(params, "SsmParametersConstruct should be created successfully")
149113
const template = Template.fromStack(stack)
150114

151-
const outputs = template.toJSON().Outputs as Record<string, {
152-
Description?: string
153-
Export?: {Name?: string}
154-
}>
115+
template.hasResourceProperties("AWS::SSM::Parameter", {
116+
Name: "mock-stack-MockParam1Suffix",
117+
Type: "String",
118+
Value: "mock-value-1",
119+
Description: "Mock SSM parameter description"
120+
})
155121

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)
122+
template.hasResourceProperties("AWS::IAM::ManagedPolicy", {
123+
Description: "Allows reading SSM parameters"
124+
})
159125
})
160126
})
161127

0 commit comments

Comments
 (0)