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

Attach Subnet to AutoScaleGroup #4604

Closed
1 of 2 tasks
fogfish opened this issue Oct 21, 2019 · 3 comments · Fixed by #4622
Closed
1 of 2 tasks

Attach Subnet to AutoScaleGroup #4604

fogfish opened this issue Oct 21, 2019 · 3 comments · Fixed by #4622
Assignees
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling feature-request A feature should be added or improved. in-progress This issue is being actively worked on.

Comments

@fogfish
Copy link
Contributor

fogfish commented Oct 21, 2019

AWS AutoScaling Groups is a tool to provision EC2 instances for various workload patterns. AWS CDK allows developers to specify vpcSubnets subnets selection (meaning existing one) but do not allow to create Subnet and ASG within same stack.

Use Case

This issue is continuation of use-cases defined in #4586. There is a need to provision backend infrastructure within own subnet. There is a stack that deploys extension to existing VPC.

const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {/* ... */})

const subnet1 = new ec2.PrivateSubnet(this, 'BE1', {
  availabilityZone: vpc.availabilityZones[0],
  // ...
})

const subnet2 = new ec2.PrivateSubnet(this, 'BE2', {
  availabilityZone: vpc.availabilityZones[1],
  // ...
})

const nodes = new asg.AutoScalingGroup(this, 'Nodes', {
   vpcSubnets: {/* impossible to pass reference to subnet1 and subnet2 */}
   // ...
})

It is impossible to associate ASG to subnets. There is only one ugly work around - you have to declare the subnets in own stack and then import to ASG using subnetGroupName. However, workaround defeats purpose of layers design (see #4586).

Proposed Solution

Option 1: brute-force design
Easy to design, implement, impacts only AutoScalingGroup. I do not like it.

Enhance the property type vpcSubnets: SubnetSelection | string[]. Then modify following code to either pick subnets id as-is or query data from vpc.

https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts#L488

Option 2: support explicit subnet definition with SubnetSelection

Give possibility to explicitly declare subnets ID as part of the subnet selection query

interface SubnetSelection {
   /**
   * Select the subnet group with the given ids
   */
   readonly subnetIds?: ISubnet[];
}

then support this attribute at VPC.selectSubnets(...), which acts roughly as transform function which maps ISubnet to SelectedSubnets.

I'd recommend a second approach, it allows to support subnet assignment to other classes as well. Not only too ASG.

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@fogfish fogfish added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 21, 2019
@SomayaB SomayaB added the @aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling label Oct 21, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 21, 2019

You seem to be asking for selection of individual subnets, is that right?

@fogfish
Copy link
Contributor Author

fogfish commented Oct 21, 2019

Yes, for selection of individual subnets, which are created within same template as ASG. What do you think about option 2? I do have a strong feeling that it suites other use-cases.

@hoegertn
Copy link
Contributor

I love option 2. I need the case where I want to launch an ASG in only one zone. This could be solved with the same approach.

@SomayaB SomayaB added in-progress This issue is being actively worked on. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 22, 2019
@mergify mergify bot closed this as completed in #4622 Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-autoscaling Related to Amazon EC2 Auto Scaling feature-request A feature should be added or improved. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants