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

feat(rds): allow using existing security groups for new instance #4495

Merged
merged 9 commits into from
Oct 24, 2019

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Oct 14, 2019

Closes #2949

BREAKING CHANGE: securityGroup: ec2.ISecurityGroup is now securityGroups: ec2.ISecurityGroup[] in DatabaseInstanceAttributes, removed securityGroupId from IDatabaseInstance


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

@jogold jogold requested a review from skinny85 as a code owner October 14, 2019 12:49
@mergify
Copy link
Contributor

mergify bot commented Oct 14, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @jogold ! One comment.

*
* @default - a new security group is created
*/
readonly securityGroup?: ec2.ISecurityGroup;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can have an array of SecurityGroups for instance, right? So this should be readonly securityGroups: ec2.ISecurityGroup[], correct?

Copy link
Contributor Author

@jogold jogold Oct 14, 2019

Choose a reason for hiding this comment

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

Agree but this is to be consistent with other packages/resources in the CDK, examples are ECS Service, RDS Cluster, ELBV2 Load balancers, Lambda functions, etc. All those resources accept an array of security groups but it's always implemented with a single security group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only exception is the AWS CodeBuild project.

Copy link
Contributor

Choose a reason for hiding this comment

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

I discussed this with the team, and we came to the conclusion that array is the way to go, and the other places that don't allow arrays are actually the ones that are wrong (and they will have to change, like ECS does in #3985 ).

So, please change it to readonly securityGroups: ISecurityGroup[].

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Note there's now a BREAKING CHANGE documented in the PR description, someone of the team will need to squash this PR because mergify won't take it into account.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the breaking change removing the securityGroupId property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BREAKING CHANGE: securityGroup: ec2.ISecurityGroup is now securityGroups: ec2.ISecurityGroup[] in DatabaseInstanceAttributes, removed securityGroupId from IDatabaseInstance

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'm missing something then. Wasn't it possible to use existing security groups with Instance before this PR? When you could pass in a single security group?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I think I see it now. It's about allowing to use an existing security group for a new Instance, right? Before, it was only possible to pass it for imported Instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly

@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 17, 2019

Something unrelated to this PR, hope that's okay. @jogold I want to ask you something privately. To that end, I sent an email address to the email address you use to sign your GitHub commits (jonathan@***exchange.be). No rush, but in case you don't use that email address anymore, can you please shoot me a quick line from your current address at huijbers@amazon.com ?

Thanks a lot!

@jogold
Copy link
Contributor Author

jogold commented Oct 17, 2019

@rix0rrr just replied to your email 👍

@mergify mergify bot dismissed skinny85’s stale review October 18, 2019 18:26

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@jogold jogold changed the title feat(rds): allow using existing security group for instance feat(rds): allow using existing security group for new instance Oct 19, 2019
@jogold jogold changed the title feat(rds): allow using existing security group for new instance feat(rds): allow using existing security groups for new instance Oct 19, 2019
@@ -935,7 +933,7 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
});

this.connections = new ec2.Connections({
securityGroups: [this.securityGroup],
securityGroups: this.securityGroups,
defaultPort: ec2.Port.tcp(this.instanceEndpoint.port)
Copy link
Contributor

@skinny85 skinny85 Oct 22, 2019

Choose a reason for hiding this comment

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

I see this code:

    this.connections = new ec2.Connections({
      securityGroups: this.securityGroups,
      defaultPort: ec2.Port.tcp(this.instanceEndpoint.port)
    });

is repeated in DatabaseInstance, DatabaseInstanceFromSnapshot and DatabaseInstanceReadReplica. Is there any way we can reduce this duplication?

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

One more teeny comment, if you'll bear with me :)


protected readonly vpcPlacement?: ec2.SubnetSelection;
protected readonly newCfnProps: CfnDBInstanceProps;
protected readonly securityGroup: ec2.SecurityGroup;
protected readonly securityGroups: ec2.ISecurityGroup[];
Copy link
Contributor

Choose a reason for hiding this comment

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

So, now that you moved creating connections here - is there any need to have this field? I believe the field can now be removed, and securityGroups can be just a local variable of the constructor of DatabaseInstanceNew, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct!

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for your patience!

@mergify
Copy link
Contributor

mergify bot commented Oct 24, 2019

Thank you for contributing! Your pull request is now being automatically merged.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • 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 ef1ce5e into aws:master Oct 24, 2019
@jogold
Copy link
Contributor Author

jogold commented Oct 25, 2019

@skinny85 it has been merged by mergify... it doesn't have the BREAKING CHANGE in the commit message.

@skinny85
Copy link
Contributor

@skinny85 it has been merged by mergify... it doesn't have the BREAKING CHANGE in the commit message.

Thanks for letting me know. I'll be doing the CDK release next week (probably Monday or Tuesday), remind me to add this to the Changelog's BREAKING CHANGES section 🙂.

@jogold jogold deleted the rds-existing-sg branch October 28, 2019 08:52
@jogold jogold mentioned this pull request Oct 28, 2019
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.

Ability to add an existing security group to a RDS database
4 participants