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: add subnets prop to GuScheduledEcsTask #1891

Merged
merged 3 commits into from
Jun 15, 2023
Merged

Conversation

marsavar
Copy link
Contributor

What does this change?

Adds a new optional prop to this pattern.

When attempting to synth a template, the command fails with this error message:

 There are no 'Private' subnet groups in this VPC.

This is expected - it's not possible to know what kinds of subnets are in a given VPC at compile time if a context file isn't present. Passing in this prop should address the issue and make synth work.

How to test

I made this change to my local version of GuCDK and updated package.json to point to the version of GuCDK in my filesystem rather than the one from npm, so that I was able to test this change in my stack. After passing in private subnets obtained with GuVpc.subnetsFromParameter I was able to synth without errors.

How can we measure success?

We don't have to commit a context file to version control when using this pattern.

Checklist

  • I have listed any breaking changes, along with a migration path 1
  • I have updated the documentation as required for the described changes 2

Footnotes

  1. Consider whether this is something that will mean changes to projects that have already been migrated, or to the CDK CLI tool. If changes are required, consider adding a checklist here and/or linking to related PRs.

  2. If you are adding a new construct or pattern, has new documentation been added? If you are amending defaults or changing behaviour, are the existing docs still valid?

to address synth failure due to not knowing what kinds of subnets are
present in a VPC at compile time
@marsavar marsavar requested a review from a team as a code owner June 13, 2023 11:02
@philmcmahon
Copy link
Contributor

Thanks for sorting this @marsavar ! Looks like an omission on my side

Copy link
Contributor

@nicl nicl left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -200,6 +202,7 @@ export class GuEcsTask extends Construct {

const task = new EcsRunTask(scope, `${id}-task`, {
cluster,
subnets: { subnets },
Copy link
Member

Choose a reason for hiding this comment

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

I think we can be more opinionated here, and always place the task in the private subnet (similar to how we implement EC2 apps). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it but wondered whether there were any use cases where a consumer would want the task in the public subnet. Couldn't really come up with any.
I think your suggestion makes a lot of sense, especially since we have a precedent in the way we do EC2 apps. Will default to private subnets then, and document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were you imagining something like this?

const privateSubnets = GuVpc.subnetsFromParameter(scope, { type: SubnetType.PRIVATE, app });

const task = new EcsRunTask(scope, `${id}-task`, {
    cluster,
    subnets: { subnets: privateSubnets },
    ...
}

This would effectively make the subnets prop redundant, since we're defining the subnets in the pattern constructor.

Copy link
Member

Choose a reason for hiding this comment

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

That would work. If you wanted to keep the subnets prop1, would recommend providing the destructuring with default values pattern (see taskTimeoutInMinutes above, as an example).

Footnotes

  1. Would recommend documenting the existence of this prop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All done, thanks. Have also added a couple of tests.
Let me know if I need to do anything else before I merge! :-)

@@ -3,6 +3,107 @@
exports[`The GuEcsTask pattern should create the correct resources with lots of config 1`] = `
{
"Mappings": {
"DefaultCrNodeVersionMap": {
Copy link
Member

Choose a reason for hiding this comment

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

Do we know where these new mappings originate from? Feels unrelated to the change we're making in this PR, so it's surprising to see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite sure - I think I deleted the snapshot file while working on this, and rerunning the test generated these mappings. 🫠

Copy link
Member

@akash1810 akash1810 left a comment

Choose a reason for hiding this comment

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

Worth noting that service-catalogue takes a slightly different approach to ECS than the GuCDK library, namely it:

  • Places all tasks in one cluster (GuCDK creates a cluster per task)
  • Implements a VPC work-around

Appreciate this isn't strictly related to this PR, but worth considering.

@marsavar marsavar merged commit 582b17f into main Jun 15, 2023
@marsavar marsavar deleted the ms-scheduled-ecs-subnet branch June 15, 2023 10:29
marsavar added a commit that referenced this pull request Jun 16, 2023
Passing subnets to the construct causes CDK to generate custom resources
Reverting this while the issue is being investigated.
@marsavar marsavar mentioned this pull request Jun 16, 2023
1 task
marsavar added a commit that referenced this pull request Jun 20, 2023
Passing subnets to the construct causes CDK to generate custom resources
Reverting this while the issue is being investigated.
marsavar added a commit that referenced this pull request Jun 20, 2023
* revert: revert #1891

Passing subnets to the construct causes CDK to generate custom resources
Reverting this while the issue is being investigated by AWS.
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.

4 participants