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

fix(autoscaling): error not thrown when associatePublicIpAddress is set to false when specifying launchTemplate #21714

Merged
merged 3 commits into from
Aug 25, 2022

Conversation

peterwoodworth
Copy link
Contributor

@peterwoodworth peterwoodworth commented Aug 22, 2022

Setting associatePublicIpAddress prop when also setting launchTemplate prop on a new ASG is supposed to throw an error, but doesn't due to associatePublicIpAddress being a boolean, and the error message not triggering if a falsy value is used for the prop. This PR will ensure an error is thrown when associatePublicIpAddress is set, even when the value passed is falsy. It also updates the documentation on all props which conflict with launchTemplate or mixedInstancesPolicy

fixes: #21576


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Aug 22, 2022

@github-actions github-actions bot added the p2 label Aug 22, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 22, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team August 22, 2022 21:26
@@ -543,7 +553,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
/**
* Type of instance to launch
*
* `launchTemplate` must not be specified when this property is specified.
* Cannot specify this property when `launchTemplate` or `mixedInstancesPolicy` are specified
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment stands for each instance here (I won't repeat it because that's just kind of annoying), but I think we actually want the original style comment of:

`whatever` must not be specified when `whatever-else` is specified.

@@ -1523,7 +1533,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
if (props.instanceMonitoring) {
throw new Error('Setting \'instanceMonitoring\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set');
}
if (props.associatePublicIpAddress) {
if (props.associatePublicIpAddress || props.associatePublicIpAddress === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get why setting it to false should be an issue here. It seems like we're mishandling it somewhere else and that's where we need to apply the fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be simplified to if (props.associatePublicIpAddress !== undefined).

It looks like if you specify the launchTemplate then you must specify the associatePublicIpAddress on the LaunchTemplate and not the AutoScalingGroup. The problem in the linked issue is that associatePublicIpAddress must be specified in the LaunchTemplate.networkInterfaces property which is not currently supported, which means that you can't use launchTemplate and set associatePublicIpAddress: false currently. Which is not great.

I think long term we should deprecate the AutoScalingGroup construct and create a AutoScalingGroupV2 (or something) which accepts an ILaunchConfiguration instead of just having all the properties for a LaunchConfiguration in the AutoScalingGroupProps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, the design here isn't too great. However I'm not sure what we can do for now except ensure the error gets thrown.

@@ -217,6 +223,8 @@ export interface CommonAutoScalingGroupProps {
* You can use block device mappings to specify additional EBS volumes or
* instance store volumes to attach to an instance when it is launched.
*
* `launchTemplate` and `mixedInstancesPolicy` must not be specified when this property is specified
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@mergify
Copy link
Contributor

mergify bot commented Aug 25, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 1bf056c
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit da61adc into main Aug 25, 2022
@mergify mergify bot deleted the peterwoodworth/autoscalingPropBug branch August 25, 2022 16:28
@mergify
Copy link
Contributor

mergify bot commented Aug 25, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

josephedward pushed a commit to josephedward/aws-cdk that referenced this pull request Aug 30, 2022
…et to false when specifying launchTemplate (aws#21714)

Setting `associatePublicIpAddress` prop when also setting `launchTemplate` prop on a new ASG is supposed to throw an error, but doesn't due to `associatePublicIpAddress` being a boolean, and the error message not triggering if a falsy value is used for the prop. This PR will ensure an error is thrown when `associatePublicIpAddress` is set, even when the value passed is falsy. It also updates the documentation on all props which conflict with `launchTemplate` or `mixedInstancesPolicy`

fixes: aws#21576

----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutoScalingGroupProps.AssociatePublicIpAddress has no effect
4 participants