Skip to content

Allow configuring subnetworks in GCP settings - #4274

Draft
jagretti wants to merge 1 commit into
dstackai:masterfrom
jagretti:issue_4254_gcp_subnetwork
Draft

Allow configuring subnetworks in GCP settings#4274
jagretti wants to merge 1 commit into
dstackai:masterfrom
jagretti:issue_4254_gcp_subnetwork

Conversation

@jagretti

@jagretti jagretti commented Sep 8, 2026

Copy link
Copy Markdown

Closes #4254

Adds an optional subnetworks field to the GCP backend config — a mapping from regions to subnet names in the VPC specified by vpc_name:

projects:
- name: main
  backends:
  - type: gcp
    project_id: my-project
    regions: [europe-west4]
    vpc_name: my-vpc
    subnetworks:
      europe-west4: my-subnet
    creds:
      type: default

Previously, dstack always provisioned in the first usable subnet returned by ListUsableSubnetworks for the VPC and region, with no way to influence the choice. This is limiting when a VPC has multiple subnets in the same region serving different purposes — especially for private gateways and fleets with public_ip: false, where clients can only reach the VMs if they land in a subnet the client network routes to.

Behavior

  • In mapped regions, instances, gateways, and TPUs are provisioned in the specified subnet (matched by name against usable subnets of the VPC; shared VPCs supported).
  • In unmapped regions, behavior is unchanged: any usable subnet of the VPC is used. With subnetworks unset, behavior is identical to before.
  • Backend config validation errors early if subnetworks is set without vpc_name, if it's keyed by a region not in regions, or if a mapped subnet doesn't exist in its region (the error lists the available subnets).
  • extra_vpcs/roce_vpcs subnet selection is unchanged (out of scope).

The field shape and behavior mirror the Azure subnet_ids setting (#3955).

Testing

  • New unit tests for subnet matching (TestGetVpcSubnetOrError) and configurator validation; uv run pytest src/tests/_internal/core/backends/gcp/ passes.
  • Docs updated in concepts/backends.md; the reference page picks up the field description from the model schema.

🤖 Generated with Claude Code

Similarly to `vpc_name`, allow selecting specific subnets
dstack provisions instances and gateways in, mapped per region.
Regions not mapped keep using any usable subnet of the VPC.

Closes dstackai#4254

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

[Feature] GCP backend: allow specifying the subnetwork (currently always picks the first usable subnet in the VPC)

1 participant