diff --git a/src/constructs/core/parameters.test.ts b/src/constructs/core/parameters.test.ts index f7d96dcacb..ff7c53b60b 100644 --- a/src/constructs/core/parameters.test.ts +++ b/src/constructs/core/parameters.test.ts @@ -8,8 +8,8 @@ import { GuAmiParameter, GuArnParameter, GuInstanceTypeParameter, + GuParameter, GuS3ObjectArnParameter, - GuSSMParameter, GuStackParameter, GuStageParameter, GuStringParameter, @@ -18,6 +18,57 @@ import { } from "./parameters"; import type { GuStack } from "./stack"; +describe("The GuParameter class", () => { + it("sets the type as passed through by default", () => { + const stack = simpleGuStackForTesting(); + + new GuParameter(stack, "Parameter", { type: "Boolean" }); + + const json = SynthUtils.toCloudFormation(stack) as SynthedStack; + + expect(json.Parameters.Parameter).toEqual({ + Type: "Boolean", + }); + }); + + it("wraps the type with SSM utility is fromSSM is true", () => { + const stack = simpleGuStackForTesting(); + + new GuParameter(stack, "Parameter", { type: "Boolean", fromSSM: true }); + + const json = SynthUtils.toCloudFormation(stack) as SynthedStack; + + expect(json.Parameters.Parameter).toEqual({ + Type: "AWS::SSM::Parameter::Value", + }); + }); + + it("defaults to string if SSM is true but no type provided", () => { + const stack = simpleGuStackForTesting(); + + new GuParameter(stack, "Parameter", { fromSSM: true }); + + const json = SynthUtils.toCloudFormation(stack) as SynthedStack; + + expect(json.Parameters.Parameter).toEqual({ + Type: "AWS::SSM::Parameter::Value", + }); + }); + + it("passes through other values without modification", () => { + const stack = simpleGuStackForTesting(); + + new GuParameter(stack, "Parameter", { type: "Boolean", fromSSM: true, description: "This is a test" }); + + const json = SynthUtils.toCloudFormation(stack) as SynthedStack; + + expect(json.Parameters.Parameter).toEqual({ + Type: "AWS::SSM::Parameter::Value", + Description: "This is a test", + }); + }); +}); + describe("The GuStringParameter class", () => { it("should set the type to string", () => { const stack = simpleGuStackForTesting(); @@ -101,36 +152,6 @@ describe("The GuInstanceTypeParameter class", () => { }); }); -describe("The GuSSMParameter class", () => { - it("should combine default, override and prop values", () => { - const stack = simpleGuStackForTesting(); - - new GuSSMParameter(stack, "Parameter", { description: "This is a test" }); - - const json = SynthUtils.toCloudFormation(stack) as SynthedStack; - - expect(json.Parameters.Parameter).toEqual({ - NoEcho: true, - Type: "AWS::SSM::Parameter::Value", - Description: "This is a test", - }); - }); - - it("let's you override default props", () => { - const stack = simpleGuStackForTesting(); - - new GuSSMParameter(stack, "Parameter", { noEcho: false, description: "This is a test" }); - - const json = SynthUtils.toCloudFormation(stack) as SynthedStack; - - expect(json.Parameters.Parameter).toEqual({ - NoEcho: false, - Type: "AWS::SSM::Parameter::Value", - Description: "This is a test", - }); - }); -}); - describe("The GuSubnetListParameter class", () => { it("should combine override and prop values", () => { const stack = simpleGuStackForTesting(); diff --git a/src/constructs/core/parameters.ts b/src/constructs/core/parameters.ts index 35a46e6f5e..23a7be7473 100644 --- a/src/constructs/core/parameters.ts +++ b/src/constructs/core/parameters.ts @@ -3,13 +3,18 @@ import { CfnParameter } from "@aws-cdk/core"; import { RegexPattern, Stage, Stages } from "../../constants"; import type { GuStack } from "./stack"; -export type GuParameterProps = CfnParameterProps; +export interface GuParameterProps extends CfnParameterProps { + fromSSM?: boolean; +} export type GuNoTypeParameterProps = Omit; export class GuParameter extends CfnParameter { constructor(scope: GuStack, id: string, props: GuParameterProps) { - super(scope, id, props); + super(scope, id, { + ...props, + type: props.fromSSM ? `AWS::SSM::Parameter::Value<${props.type ?? "String"}>` : props.type, + }); } } @@ -51,16 +56,6 @@ export class GuInstanceTypeParameter extends GuParameter { } } -export class GuSSMParameter extends GuParameter { - constructor(scope: GuStack, id: string, props: GuNoTypeParameterProps) { - super(scope, id, { - noEcho: true, - ...props, - type: "AWS::SSM::Parameter::Value", - }); - } -} - export class GuSubnetListParameter extends GuParameter { constructor(scope: GuStack, id: string, props: GuNoTypeParameterProps) { super(scope, id, { ...props, type: "List" }); diff --git a/src/constructs/iam/policies/log-shipping.ts b/src/constructs/iam/policies/log-shipping.ts index 1557e91664..a3bcfa873f 100644 --- a/src/constructs/iam/policies/log-shipping.ts +++ b/src/constructs/iam/policies/log-shipping.ts @@ -1,6 +1,6 @@ import { Effect, PolicyStatement } from "@aws-cdk/aws-iam"; import type { GuStack } from "../../core"; -import { GuSSMParameter } from "../../core"; +import { GuStringParameter } from "../../core"; import type { GuPolicyProps } from "./base-policy"; import { GuPolicy } from "./base-policy"; @@ -8,9 +8,10 @@ export class GuLogShippingPolicy extends GuPolicy { constructor(scope: GuStack, id: string = "GuLogShippingPolicy", props?: GuPolicyProps) { super(scope, id, { ...props }); - const loggingStreamNameParam = new GuSSMParameter(scope, "LoggingStreamName", { + const loggingStreamNameParam = new GuStringParameter(scope, "LoggingStreamName", { description: "SSM parameter containing the Name (not ARN) on the kinesis stream", default: "/account/services/logging.stream.name", + fromSSM: true, }); this.addStatements( diff --git a/src/patterns/__snapshots__/instance-role.test.ts.snap b/src/patterns/__snapshots__/instance-role.test.ts.snap index c34aff7ee2..a39b550c02 100644 --- a/src/patterns/__snapshots__/instance-role.test.ts.snap +++ b/src/patterns/__snapshots__/instance-role.test.ts.snap @@ -223,7 +223,6 @@ Object { "LoggingStreamName": Object { "Default": "/account/services/logging.stream.name", "Description": "SSM parameter containing the Name (not ARN) on the kinesis stream", - "NoEcho": true, "Type": "AWS::SSM::Parameter::Value", }, "Stack": Object {