aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

feat(ecs): allow adding security group(s) after construction via connections.addSecurityGroup()

Open hamilton-earthscope opened this issue 1 year ago • 2 comments

Allow easily adding Security Groups to ECS Services after the L2 Service has already been instantiated by using the service's .connections.addSecurityGroup().

Issue # (if applicable)

Closes #17269.

Related to #16117

Reason for this change

Currently, the only way to add additional security groups to the ECS Service outside of the constructor is to use escape hatches.

   const cfnService = service.node.defaultChild as CfnService;
    cfnService.addPropertyOverride(
      "NetworkConfiguration.AwsvpcConfiguration.SecurityGroups",
      [
        ...service.connections.securityGroups.map((sg) => sg.securityGroupId),
        someOtherSecurityGroupThatWasCreatedLater.securityGroupId,
      ],
    );

Description of changes

Use Lazy.list to set the service's security groups to its connections objects' security groups at synth-time.

This allows users to call service.connections.addSecurityGroup(someOtherSecurityGroupThatWasCreatedLater) at any point in their app and have someOtherSecurityGroupThatWasCreatedLater end up in the service's security groups at synth-time.

Description of how you validated changes

I added one test to fargate-service.test.ts

Checklist


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

hamilton-earthscope avatar Sep 13 '24 23:09 hamilton-earthscope

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 82.38%. Comparing base (e6f5bc8) to head (ac89b4e). :warning: Report is 818 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #31447   +/-   ##
=======================================
  Coverage   82.38%   82.38%           
=======================================
  Files         120      120           
  Lines        6937     6937           
  Branches     1170     1170           
=======================================
  Hits         5715     5715           
  Misses       1119     1119           
  Partials      103      103           
Flag Coverage Δ
suite.unit 85.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 85.26% <ø> (ø)
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Mar 18 '25 10:03 codecov[bot]

AWS CodeBuild CI Report

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

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

aws-cdk-automation avatar Mar 18 '25 10:03 aws-cdk-automation

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing

To prevent automatic closure:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 14 days if no action is taken.

aws-cdk-automation avatar Aug 05 '25 00:08 aws-cdk-automation

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

aws-cdk-automation avatar Aug 20 '25 00:08 aws-cdk-automation

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

github-actions[bot] avatar Aug 20 '25 00:08 github-actions[bot]