GCP Python API viability — research findings
Yes, viable. Google maintains official Python clients for everything we need. Here's the lay of the land mapped onto our CloudProvider abstraction (machine/provider.py:32):
Libraries
| Capability | Library | Notes |
|---|---|---|
| VM lifecycle | google-cloud-compute |
compute_v1.InstancesClient with insert/get/delete/list — clean mapping to create_vm/get_vm/destroy_vm/list_vms |
| DNS | google-cloud-dns |
Manages "managed zones" + resource record sets — maps to create_dns_record/delete_dns_record/get_dns_records/list_domains |
| Auth | google-auth (transitive) |
Application Default Credentials — service account JSON or gcloud auth application-default login |
Both are official, actively maintained, and BSD/Apache-licensed. They'll fit in the same shiv bundle, though they're heavier than python-digitalocean and pull in gRPC + protobuf (notably bigger build artifact).
Three frictions worth knowing before you commit
- SSH keys don't fit the existing model cleanly. DO and Vultr both have a server-side "named SSH key registry" you can list and reference by name. GCP doesn't — keys live in either:
- Project metadata under the
ssh-keyskey (one big newline-separated string likeuser:ssh-rsa AAAA... comment) - Per-instance metadata at create time
- OS Login (recommended modern path), which ties access to IAM identities instead of named keys
list_ssh_keys() and get_ssh_key(name) would have to synthesize "name" from the username prefix in each metadata entry. Not hard, just lossy.
-
Projects work differently. In GCP, every resource lives inside a project and the project ID is fixed at client construction — you can't
assign_to_projecta VM after creation the way DO supports. The existinglist_projects/assign_to_projectmethods onCloudProviderwould likely become no-ops, with the project ID coming from config instead. -
Region vs. zone. GCP requires a zone (e.g.
us-central1-a) for instance creation, not just a region. The existingregionparameter would need to accept either, or we pick a default zone within the region.
Config shape (suggested)
gcp:
project-id: my-gcp-project
credentials-file: ~/.config/gcloud/service-account.json # or rely on ADC
default-zone: us-central1-a
Recommendation
Go with google-cloud-compute + google-cloud-dns. The mapping is straightforward except for SSH keys, where I'd suggest treating project-metadata keys as the equivalent of DO's named keys (username = name) for the MVP, and leave OS Login as a future option.
Want me to sketch the GcpProvider skeleton next, or look deeper into any of these (e.g. shiv bundle size impact, OS Login alternative)?
Sources: - google-cloud-compute on PyPI - Compute Engine Python sample: create_instance.py - Python Client for Cloud DNS API - Add SSH keys to VMs (project metadata) - About SSH connections / OS Login