Skip to content

Commit

Permalink
change imageId prop to GuAmiParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Lynch committed Jan 29, 2021
1 parent 2005fa7 commit 10502b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/constructs/autoscaling/asg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApplicationProtocol } from "@aws-cdk/aws-elasticloadbalancingv2";
import { Stack } from "@aws-cdk/core";
import { simpleGuStackForTesting } from "../../../test/utils/simple-gu-stack";
import type { SynthedStack } from "../../../test/utils/synthed-stack";
import { GuAmiParameter } from "../core";
import { GuSecurityGroup } from "../ec2";
import { GuApplicationTargetGroup } from "../loadbalancing";
import type { GuAutoScalingGroupProps } from "./asg";
Expand Down Expand Up @@ -43,14 +44,21 @@ describe("The GuAutoScalingGroup", () => {
test("does not add the AMI parameter if an imageId prop provided", () => {
const stack = simpleGuStackForTesting();

new GuAutoScalingGroup(stack, "AutoscalingGroup", { ...defaultProps, osType: 1, imageId: "123" });
new GuAutoScalingGroup(stack, "AutoscalingGroup", {
...defaultProps,
osType: 1,
imageId: new GuAmiParameter(stack, "CustomAMI", {}),
});

const json = SynthUtils.toCloudFormation(stack) as SynthedStack;

expect(Object.keys(json.Parameters)).not.toContain("AMI");
expect(Object.keys(json.Parameters)).toContain("CustomAMI");

expect(stack).toHaveResource("AWS::AutoScaling::LaunchConfiguration", {
ImageId: "123",
ImageId: {
Ref: "CustomAMI",
},
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/constructs/autoscaling/asg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GuAmiParameter, GuInstanceTypeParameter } from "../core";
export interface GuAutoScalingGroupProps
extends Omit<AutoScalingGroupProps, "imageId" | "osType" | "machineImage" | "instanceType" | "userData"> {
instanceType?: InstanceType;
imageId?: string;
imageId?: GuAmiParameter;
osType?: OperatingSystemType;
machineImage?: MachineImage;
userData: string;
Expand All @@ -31,7 +31,7 @@ export class GuAutoScalingGroup extends AutoScalingGroup {
osType: props.osType ?? OperatingSystemType.LINUX,
userData: UserData.custom(props.userData),
imageId:
props.imageId ??
props.imageId?.valueAsString ??
new GuAmiParameter(scope, "AMI", {
description: "AMI ID",
}).valueAsString,
Expand Down

0 comments on commit 10502b0

Please sign in to comment.