Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow imageId and instanceType to be passed into ASG #213

Merged
merged 3 commits into from
Jan 29, 2021

Conversation

jamie-lynch
Copy link
Contributor

What does this change?

Currently the GuAutoscalingGroup creates parameters for the imageId (AMI) and instanceType values and omits the props. This PR adds the props back in as optional and only creates the parameters if no value is passed. This maintains the BYO pattern as the default behaviour but allows flexibility where required.

Does this change require changes to existing projects or CDK CLI?

No

How to test

New unit tests have been written to cover the change in behaviour.

How can we measure success?

The default behaviour of our constructs makes them easy to use but also allows for flexibility.

@jamie-lynch jamie-lynch requested a review from a team January 28, 2021 14:27
@@ -40,7 +40,21 @@ describe("The GuAutoScalingGroup", () => {
});
});

test("adds the instanceType parameter", () => {
test("does not add the AMI parameter if an imageId prop provided", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that Riff-Raff currently relies on AMI being configured as a parameter in order to automatically update the underlying AMI during a deployment. That's a widely used feature in the department (and ideally we want every application to do this due to the security benefits it brings), so I think we might need to discourage passing it as a prop for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. The reason this was added back as an optional prop was to allow for stacks that have multiple ASGs. Currently, that would fail as we'd try to create the same parameter more than once. This would allow a stack to define multiple parameters and pass them into each ASG as required. If we want to go as far as requiring AMI values to be a parameter, we could change the type of imageId to GuAMIParameter to allow for this overriding but prevent the value being hardcoded in the stack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this was added back as an optional prop was to allow for stacks that have multiple ASGs.

Hmm, I hadn't thought about that other use-case! Maybe we should still allow this then and use patterns/docs to push 'typical' single-ASG stacks towards using an AMI parameter.

Copy link
Contributor Author

@jamie-lynch jamie-lynch Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a suggestion below which might be the best of both worlds. Agreed that the standard EC2 pattern should then just create the parameter for you!

@jacobwinch
Copy link
Contributor

I wonder if we should go even further for instanceType and steer users away from using a parameter for this value entirely. @akash1810 described some of the advantages of using Mappings for min/max values in this thread and I think that the same logic applies to instanceType (which is, to my mind at least, not private).

In addition to the benefits @akash1810 mentioned, using a Mapping is also neater if you deploy your CFN changes via Riff-Raff, because it allows you to update instanceType via merging a PR instead of via manually CloudForming in the console (which is required when using a parameter).

If we included a default InstanceType in a Mappings section in the (soon to exist!) GuEc2App pattern, I wonder if people really need the option to use a parameter for this at all?

Copy link
Contributor

@jacobwinch jacobwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I've raised a couple of questions about the approach, I think this is a step in the right direction and the code looks great, so feel free to merge if you want to keep things moving 🚢

@@ -11,6 +11,8 @@ import { GuAmiParameter, GuInstanceTypeParameter } from "../core";
// https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys
export interface GuAutoScalingGroupProps
extends Omit<AutoScalingGroupProps, "imageId" | "osType" | "machineImage" | "instanceType" | "userData"> {
instanceType?: InstanceType;
imageId?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require the prop to be a parameter so we can cater for stacks with multiple ASGs but enforce using parameters for AMIs.

Suggested change
imageId?: string;
imageId?: GuAMIParameter;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice idea 👍

Copy link
Contributor

@jacobwinch jacobwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 👍

@jamie-lynch jamie-lynch merged commit 181170f into main Jan 29, 2021
@jamie-lynch jamie-lynch deleted the jl/asg-defaults branch January 29, 2021 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants