Skip to content

fix(launch): honour --vpc instead of always using the default VPC - #700

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/673-honour-vpc-flag
Oct 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/673-honour-vpc-flag

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #673. The last of the three flags #688's wiring gate turned up, and the only one that needed implementing rather than deprecating.

The bug

--vpc was bound to a package global that nothing read. There was no VPCID field on LaunchConfig at all, and all five consumers called GetDefaultVPC unconditionally — so spawn launch --vpc vpc-0abc… was accepted, exited 0, and launched the instance in the default VPC, with its managed security group created there too.

Silent, and it lands on network placement: wrong subnet, wrong route table, no route to an EFS or FSx mount target, and SG rules written into a VPC the instance is not in. An account whose research VPC is not the default could not target a VPC at all.

One resolver, not five fixes

All five launch-path sites now go through ResolveVPC(ctx, region, explicit):

site what it decides
MPI security group which VPC the spawn-mpi-* group lives in
Windows security group same, for RDP/SSH
FSx subnet (no --subnet-id) where the filesystem is created
GetSubnetForAZ the AZ's subnet, for FSx co-location
(gate) no launch-path file may call GetDefaultVPC directly

The storage sites matter as much as the SG ones, and they are the ones easy to miss: a filesystem created in the default VPC while the instance is in another presents as a broken mount, not as a dropped flag. The reporter would spend the debugging time on NFS and security groups.

I made it a shared resolver rather than four separate edits deliberately. Five sites each independently assuming the default VPC is why this flag did nothing, and fixing some while leaving others is precisely how #539 and #667 each ended up fixed on one path and broken on another. The class gate fails the build on a direct GetDefaultVPC call from the launch path, so the sixth site can't reintroduce it.

cmd/app.go, cmd/image.go and pkg/doctor still call GetDefaultVPC and are excluded from the gate on purpose — they are not launches and have no --vpc to honour.

--vpc + --subnet-id

Validated up front. Passing both is the natural way to use --vpc, and EC2's own error for a mismatch arrives only at RunInstances and names neither flag:

--subnet-id subnet-abc is in VPC vpc-111, but --vpc says vpc-222; pass one or make them agree

Advisory on a DescribeSubnets failure rather than fail-closed — EC2 still rejects a genuine mismatch, so this is a better error, not a new gate that a describe hiccup could turn into a failed launch.

Verification

Three gates, each confirmed to fail when its half is reverted:

  • removing the flag copy → VPCID = "", want "vpc-0abc…"
  • restoring one direct GetDefaultVPC → names the file and line
  • removing the FSx threading → explains that the mount could not route

I checked each by reverting and watching it fail, because four tests I wrote earlier today passed vacuously.

Standard gates: gofmt -l empty, go vet ./..., go test -short ./... (including the full pkg/aws suite), make check-docs regenerated, changelog gate, semgrep → 0 findings.

Not hardware-verified. The flag plumbing is pure and the gates cover the call sites, but "the security group is created in the right VPC and the FSx mount routes" is an AWS-side claim. make smoke-needed flags pkg/aws/securitygroup.go and cmd/launch_single.go, so this is covered by the smoke before the next tag — a launch with --vpc pointing at a non-default VPC would settle it.

Housekeeping

--vpc is removed from knownUnwiredFlags; only --cartesian and --use-reservation remain there, both now deliberately deprecated rather than pending. In sweepFlagCoverage it stays a known gap, re-pointed at #697 — implemented for single launches, still dropped on sweeps.

The flag was bound to a global nothing read — there was no VPCID field
on LaunchConfig at all — and all five consumers called GetDefaultVPC
unconditionally. So --vpc was accepted, exited 0, and launched in the
DEFAULT VPC with its security group created there too.

All five sites now go through one ResolveVPC: the MPI and Windows
security groups, FSx's subnet choice when --subnet-id is absent, and
GetSubnetForAZ. The storage paths matter as much as the SG ones — a
filesystem in the default VPC while the instance is elsewhere presents
as a broken mount, not a dropped flag.

--vpc with --subnet-id is validated up front, since EC2's own mismatch
error arrives only at RunInstances and names neither flag.

A gate fails the build on any direct GetDefaultVPC call from the launch
path: five sites each assuming the default is why this did nothing, and
fixing some but not others is how #539 and #667 each ended up half-fixed.

Fixes #673
@scttfrdmn
scttfrdmn merged commit 626dd84 into main Oct 5, 2026
6 checks passed
@scttfrdmn
scttfrdmn deleted the fix/673-honour-vpc-flag branch October 5, 2026 01:01
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.

--vpc is parsed and never read: the instance silently launches in the DEFAULT VPC

1 participant