Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 1 addition & 16 deletions packages/cdkConstructs/src/constructs/SsmParametersConstruct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {CfnOutput} from "aws-cdk-lib"
import {Effect, ManagedPolicy, PolicyStatement} from "aws-cdk-lib/aws-iam"
import {StringParameter} from "aws-cdk-lib/aws-ssm"
import {Construct} from "constructs"
Expand Down Expand Up @@ -107,9 +106,7 @@ export class SsmParametersConstruct extends Construct {
const {
namePrefix,
parameters,
readPolicyExportSuffix,
readPolicyDescription = "Allows reading SSM parameters",
readPolicyOutputDescription = "Access to the parameters used by the integration"
readPolicyDescription = "Allows reading SSM parameters"
} = props
Comment thread
wildjames marked this conversation as resolved.

if (parameters.length === 0) {
Expand Down Expand Up @@ -141,12 +138,6 @@ export class SsmParametersConstruct extends Construct {
})

createdParameters[parameter.id] = ssmParameter

new CfnOutput(this, `${parameter.id}ParameterNameOutput`, {
description: parameter.outputDescription ?? parameter.description,
value: ssmParameter.parameterName,
exportName: `${namePrefix}-${parameter.outputExportSuffix ?? parameter.nameSuffix}`
})
}
Comment thread
wildjames marked this conversation as resolved.

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

new CfnOutput(this, "ReadParametersPolicyOutput", {
description: readPolicyOutputDescription,
value: readParametersPolicy.managedPolicyArn,
exportName: `${namePrefix}-${readPolicyExportSuffix}`
})

this.parameters = createdParameters
this.readParametersPolicy = readParametersPolicy
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,10 @@ describe("SsmParametersConstruct", () => {
expect(statement.Action).toEqual(["ssm:GetParameter", "ssm:GetParameters"])
expect(statement.Resource).toHaveLength(3)
})

test("exports parameter names and policy ARN", () => {
const outputs = template.toJSON().Outputs as Record<string, {
Description?: string
Export?: {
Name?: string
}
}>

const exportedNames = Object.values(outputs)
.map((output) => output.Export?.Name)
.filter((name): name is string => name !== undefined)

const descriptions = Object.values(outputs)
.map((output) => output.Description)
.filter((description): description is string => description !== undefined)

expect(exportedNames).toContain("mock-stack-MockParam1Parameter")
expect(exportedNames).toContain("mock-stack-MockParam2Parameter")
expect(exportedNames).toContain("mock-stack-MockParam3Parameter")
expect(exportedNames).toContain("mock-stack-MockGetParametersPolicy")

expect(descriptions).toContain("Name of the SSM parameter holding MockParam1")
expect(descriptions).toContain("Name of the SSM parameter holding MockParam2")
expect(descriptions).toContain("Name of the SSM parameter holding MockParam3")
expect(descriptions).toContain("Mock read policy output description")
})
})
Comment thread
wildjames marked this conversation as resolved.

describe("SsmParametersConstruct uses defaults when optional fields are omitted", () => {
test("outputDescription defaults to description and outputExportSuffix defaults to nameSuffix", () => {
test("creates parameter and policy with default readPolicyDescription when optional fields are omitted", () => {
const app = new App()
Comment thread
wildjames marked this conversation as resolved.
Outdated
const stack = new Stack(app, "defaultsStack")
const params = new SsmParametersConstruct(stack, "DefaultsParameters", {
Expand All @@ -140,22 +113,24 @@ describe("SsmParametersConstruct uses defaults when optional fields are omitted"
nameSuffix: "MockParam1Suffix",
description: "Mock SSM parameter description",
value: "mock-value-1"
// outputDescription and outputExportSuffix intentionally omitted
}
]
],
readPolicyExportSuffix: "MockGetParametersPolicy"
Comment thread
wildjames marked this conversation as resolved.
Outdated
})
// Get sonar to shup up about the construct not being used
Comment thread
wildjames marked this conversation as resolved.
assert(params, "SsmParametersConstruct should be created successfully")
const template = Template.fromStack(stack)

const outputs = template.toJSON().Outputs as Record<string, {
Description?: string
Export?: {Name?: string}
}>
template.hasResourceProperties("AWS::SSM::Parameter", {
Name: "mock-stack-MockParam1Suffix",
Type: "String",
Value: "mock-value-1",
Description: "Mock SSM parameter description"
})

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

Expand Down
Loading