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(ec2): passing keypair to instance unexpectedly does nothing #28482

Merged
merged 10 commits into from
Jan 8, 2024

Conversation

ayush-shah-1501
Copy link
Contributor

@ayush-shah-1501 ayush-shah-1501 commented Dec 24, 2023

Fixes by Specifying key pair reference in cfnInstance.

This will change behavior if both keyName and keyPair is set on an existing resource, since we will use keyPair.keyPairName instead of keyName now. However, there is no correct use case for specifying both keyPair and keyName, and given keyName is deprecated, this PR is introducing the correct behavior.

Closes #28478.
Closes #28569


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

@github-actions github-actions bot added bug This issue is a bug. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Dec 24, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team December 24, 2023 05:44
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Dec 25, 2023
@ayush-shah-1501 ayush-shah-1501 changed the title fix(ec2): keypair support for ec2 chore(ec2): keypair support for ec2 Dec 25, 2023
@ayush-shah-1501
Copy link
Contributor Author

ayush-shah-1501 commented Dec 25, 2023

Exemption Request: This PR is quick fix of this PR, which didn't need changes to readme and tests.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Dec 25, 2023
@sumupitchayan
Copy link
Contributor

@ayush-shah-1501 this PR title should be fix not chore and should also include tests to validate this functionality fixes the bug

@sumupitchayan sumupitchayan removed the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Dec 28, 2023
@ayush-shah-1501 ayush-shah-1501 changed the title chore(ec2): keypair support for ec2 fix(ec2): keypair support for ec2 Dec 28, 2023
@laurelmay
Copy link
Contributor

laurelmay commented Dec 29, 2023

@ayush-shah-1501 Thanks for catching this! So sorry for missing this in the original PR. I will momentarily open a PR on your repo that will add a possible test & updates the integration tests.

Additionally, so long as a user follows the docs for how to use an existing key pair, this should not be a breaking change.

Edit: Hopefully ayush-shah-1501#1 can help address some of the linter concerns. But it may be good to ask for an Exemption Request if the linter is still mad about the integration test.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Dec 29, 2023
Add additional tests for EC2 Instance Key Pair
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 29, 2023
@ayush-shah-1501
Copy link
Contributor Author

Exemption Request: This PR is quick fix of #28138 PR

@laurelmay
Copy link
Contributor

laurelmay commented Jan 4, 2024

For what it's worth, I think it's safe to not call this a breaking change. The correct behavior is documented and it does work correctly for other resource types; this condition was just missed in the implementation for Instance. Honestly, the current behavior (with keyName deprecated and keyPair not working) is far more broken than the results of this change.

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jan 4, 2024
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

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

@kaizencc kaizencc changed the title fix(ec2): keypair support for ec2 fix(ec2): passing keypair to instance unexpectedly does nothing Jan 8, 2024
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 8, 2024
@kaizencc kaizencc added pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Jan 8, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 8, 2024 21:29

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

Copy link
Contributor

mergify bot commented Jan 8, 2024

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: 256455c
  • 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 22e6ce8 into aws:main Jan 8, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Jan 8, 2024

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).

@cponfick
Copy link
Contributor

cponfick commented Jan 10, 2024

I am not sure if this change is at fault here, but using the ´keyPair´ parameter does not set the Ref in CFN. It does nothing.

Example:

key_pair = aws_ec2.KeyPair(
            self,
            f"Keypair",
            public_key_material="some key",
        )
instance = aws_ec2.Instance(
            self,
            f"id",
            vpc=base.vpc,
            instance_type=aws_ec2.InstanceType.of(
                aws_ec2.InstanceClass.T3, aws_ec2.InstanceSize.MICRO
            ),
            machine_image=aws_ec2.MachineImage.generic_linux(
                {'eu-central-1': 'ami-0faab6bdbac9486fb'}
            ),
            key_pair=key_pair,
            # key_name=key_pair.key_pair_name,
            associate_public_ip_address=True,
            vpc_subnets=aws_ec2.SubnetSelection(
                subnet_type=aws_ec2.SubnetType.PUBLIC
            ),
        )

keyName works as expected.

@kaizencc
Copy link
Contributor

kaizencc commented Jan 10, 2024

@cponfick this hasn't been released yet. will be out in 2.119.0, which will probably go out today. let us know in a new issue if the problem persists!

@mmieluch
Copy link

I'm using a slightly higher version 2.121.1 and it's working fine for me. Thank you for the contribution!

@alastairmccormack
Copy link

Has this been regressed?

I just used aws_cdk.aws_ec2.KeyPair.from_key_pair_name() with version 2.128.0 (build d995261), and it did nothing leaving the instance with no key. I've used Instance.key_name instead and all is good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
8 participants