feat(ecs): allow adding security group(s) after construction via connections.addSecurityGroup()
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
- [x] My code adheres to the CONTRIBUTING GUIDE and DESIGN GUIDELINES
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
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.
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
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.
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.
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.