Skip to content

Support multiple subnets in the same AZ #5297

Description

@Quindrix

Problem

We would like to use multiple subnets in the same AZ so that our runners can use the additional IP address capacity. Extending the existing subnet ranges is not an option in our environment. Requiring one subnet per AZ therefore prevents us from making use of the additional capacity.

At the moment, adding a second subnet in an AZ already represented in subnet_ids causes runner creation to fail. Terraform accepts and deploys the configuration successfully, but the scale-up Lambda fails later when it calls EC2 Fleet.

We saw the following error with the multi-runner module on v7.10.1:

{
  "level": "ERROR",
  "message": "Error processing batch (size: 1): The fleet configuration contains duplicate instance pools., ignoring batch",
  "timestamp": "2026-08-06T14:50:36.440Z",
  "service": "Proj-ubuntu-2404-arm64-ephemeral-scale-up",
  "region": "eu-west-1",
  "environment": "Proj-ubuntu-2404-arm64-ephemeral",
  "module": "lambda.ts",
  "error": {
    "name": "InvalidFleetConfig",
    "message": "The fleet configuration contains duplicate instance pools.",
    "Code": "InvalidFleetConfig",
    "Error": {
      "Code": "InvalidFleetConfig",
      "Message": "The fleet configuration contains duplicate instance pools."
    }
  }
}

Example

For example, consider three configured subnets:

subnet-a1 -> eu-west-1a
subnet-a2 -> eu-west-1a
subnet-b1 -> eu-west-1b

Configuring all three subnet IDs causes the EC2 Fleet request to fail because two of the subnets are in eu-west-1a.

Cause

The control-plane Lambda generates EC2 Fleet overrides for each combination of subnet and instance type:

subnet-a1 x instance-type-1
subnet-a2 x instance-type-1
subnet-b1 x instance-type-1

EC2 Fleet treats a capacity pool as a combination of instance type and AZ. The first two overrides therefore represent the same capacity pool, even though they use different subnet IDs.

AWS rejects the complete CreateFleet request with InvalidFleetConfig, so no runner is launched.

Expected behaviour

It should be possible to configure multiple subnets in the same AZ and have the module use their combined IP address capacity. A single EC2 Fleet request should contain at most one subnet from each AZ.

Possible approach

The module could:

  1. Use DescribeSubnets to determine the AZ of each configured subnet.
  2. Group the subnets by AZ.
  3. Create subnet sets containing no more than one subnet from each AZ.

This would require adding ec2:DescribeSubnets to the control-plane Lambda permissions.

Related

This appears to be related to #2904. That issue describes the same InvalidFleetConfig: The fleet configuration contains duplicate instance pools error, but the documented workaround of requiring every subnet to be in a different AZ prevents additional same-AZ subnet capacity from being used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions