GCP
Deploy vLLM to a Google Compute Engine GPU VM (Spot by default) with an API key, a firewall rule limited to your IP, and a lifetime backstop, or to a Cloud Run GPU service that scales to zero.
- Status
- Planned
- Kind
- Hyperscaler
- Provider id
gcp- Regions and residency
- Belgium, Netherlands, Finland, Frankfurt, Paris, plus US and APAC
Use this provider
resource "hardware_profile" "gcp_t4" {
provider = "gcp"
region = "europe-west4"
accelerator {
kind = "gpu"
model = "t4"
count = 1
memory = "16GiB"
}
memory = "15GiB"
gcp {
project = "my-project-id"
machine_type = "n1-standard-4"
provisioning = "spot"
max_run_duration = "2h"
service_account = "amicu-vm@my-project-id.iam.gserviceaccount.com"
}
}A complete example is in examples/gcp-t4-spot.
Overview
apply creates one Compute Engine VM per deployment, with the GPU attached (N1) or built in (A2, A3, G2, G4), and one firewall rule for the serving port. A startup script runs the vLLM container behind amicu's key check: every route except GET /health needs the deployment's api_key. Only runtime = "vllm" is supported; llama.cpp is rejected (AMICU-CAP-016).
The VM boots the Deep Learning VM image common-cu129-ubuntu-2204-nvidia-580, which has the NVIDIA driver but not Docker. On first boot the startup script installs Docker Engine and the NVIDIA container toolkit from Docker's and NVIDIA's apt repositories. apt trusts only the repository key whose fingerprint is built into amicu. An install that a reboot or preemption cut short is finished on the next boot, and errors from other apt repositories on the image do not stop it. This adds about one to two minutes before the vLLM image pull, so a small model is usually ready 6 to 10 minutes after apply creates the VM.
The startup script reports each boot as a guest attribute on the VM (amicu/status: booting, then ready or failed:<step>). If a step fails, for example the install, the image pull, or vLLM exiting or restarting three times, apply stops waiting at once. It prints the failed step and the end of the script's log, then deletes the VM and firewall rule it created. A model that is only slow to load is left to apply's own deadline. If a Spot VM is preempted while apply waits, the error says so. Reading the report needs compute.instances.getGuestAttributes, which roles/compute.instanceAdmin.v1 includes. Without that permission, apply waits for /health until its usual deadline.
The endpoint is https://<VM IP>:8000. The VM serves a self-signed certificate that amicu generates before it creates the VM. The certificate names no host you can resolve, so clients pin it instead of trusting a CA: apply writes it to .amicu/state/<instance>.tls.crt and prints its path, its SHA-256 fingerprint and its public key pin. amicu pins it for its own health and exposure checks. A client that skips certificate verification is not protected.
curl --cacert does not work, because the certificate names no host curl can match. Pin the public key instead (apply prints the command with the pin filled in). -k only skips the CA and host name checks, and --pinnedpubkey still refuses any other key:
curl -k --pinnedpubkey 'sha256//<public key pin>' https://<VM IP>:8000/v1/models \
-H "Authorization: Bearer $CHAT_API_KEY"In Python, trust only that certificate and turn off the host name check. The handshake still has to match the certificate:
import os, ssl
import httpx
from openai import OpenAI
tls = ssl.create_default_context(cafile=".amicu/state/<instance>.tls.crt")
tls.check_hostname = False
client = OpenAI(
base_url="https://<VM IP>:8000/v1",
api_key=os.environ["CHAT_API_KEY"],
http_client=httpx.Client(verify=tls),
)The firewall rule allows only the addresses in allowed_source_cidrs, or by default this machine's public IP as a /32. amicu never opens the port to 0.0.0.0/0 unless you list it.
The API key, the Hugging Face token and the TLS private key are stored in Secret Manager (one secret each, in the deployment's region only) before the VM is created. The VM's service account reads them at boot, so they are never in instance metadata. The secret ids and the certificate fingerprint are in the record apply writes to state first, so destroy removes the secrets even after a crash.
Insecure metadata fallback
insecure_metadata_secrets = true skips Secret Manager and puts the three secrets in instance metadata, where anyone who can read the instance in the project can read them, and the console shows them. Use it only when Secret Manager cannot be used. TLS stays on.
The VM is deleted by Compute Engine after max_run_duration (default 8 hours) whatever else happens, and a preempted Spot VM is deleted too. apply writes the VM's record to state before it creates anything, tries the next zone of the region on a capacity stockout (at most 4 zones), and waits until vLLM answers. amicu destroy deletes the VM, then the firewall rule, then the secrets, confirms each is gone, and can be run again after a failure. It deletes only resources that carry amicu's owner marker (a label on the VM, a marker in the rule's description). A resource of the same name without it is left alone and reported.
Setup and credentials
Quick setup
For an existing project with billing linked, one command enables the APIs, creates the amicu-vm and amicu-run service accounts, grants you roles/iam.serviceAccountUser on them, requests GPU quota and removes the default SSH and RDP firewall rules:
examples/gcp-setup/setup.sh my-project-id europe-west4It prints the gcp {} values to paste and does not create the project or link billing. examples/gcp-setup/main.tf is the Terraform equivalent for projects managed by Terraform. Both are described in examples/gcp-setup/README.md. The rest of this section explains each step.
amicu uses Application Default Credentials: run gcloud auth application-default login, or set GOOGLE_APPLICATION_CREDENTIALS. To act as a service account, set impersonate_service_account in the block (or GOOGLE_IMPERSONATE_SERVICE_ACCOUNT). apply makes one read of the project before it writes anything, so missing credentials fail first. The caller needs permission to create and delete instances and firewall rules in the project, to create, version, set the IAM policy of and delete secrets (roles/secretmanager.admin covers it), and GPU quota in the region.
The service account
The VM runs as a service account that reads its secrets. Create one once per project; it needs no project-level roles:
gcloud iam service-accounts create amicu-vm --project my-project-idSet service_account = "amicu-vm@my-project-id.iam.gserviceaccount.com" in the gcp {} block. amicu itself grants roles/secretmanager.secretAccessor to that account on each of the deployment's secrets, one secret at a time, and never changes project-level IAM. The account that runs apply needs roles/iam.serviceAccountUser on the VM's service account, so it may attach it to a VM:
gcloud iam service-accounts add-iam-policy-binding \
amicu-vm@my-project-id.iam.gserviceaccount.com \
--member "user:you@example.com" --role roles/iam.serviceAccountUserWithout a service_account and without insecure_metadata_secrets = true, validate, plan and apply fail with AMICU-CAP-016.
| Variable | Needed for | Notes |
|---|---|---|
GOOGLE_APPLICATION_CREDENTIALS (optional) | all commands | A service-account key file. Otherwise the gcloud login is used. |
The deployment's api_key secret, for example CHAT_API_KEY | apply, and every client call | A random key (openssl rand -hex 32). It is stored in Secret Manager and read by the VM's service account at boot (instance metadata only with insecure_metadata_secrets = true). |
HF_TOKEN (optional) | Gated Hugging Face repos | Delivered the same way, as its own secret. |
AMICU_GCP_VLLM_IMAGE (optional) | Override the vLLM image | Process-wide. |
Configuration reference
The gcp {} block on a hardware_profile with provider = "gcp":
| Argument | Type | Default | Required | Notes |
|---|---|---|---|---|
project | string | none | yes | Google Cloud project id (AMICU-CAP-016 if missing). |
backend | string | compute | no | compute (a VM) or cloud_run (a Cloud Run service, see Cloud Run). |
zone | string | first zone offering the GPU | no | Pins one zone. Otherwise the catalog zones of region that offer the GPU are tried in order. |
machine_type | string | smallest catalog machine for the GPU | no | For N1 GPUs (T4, V100, P4) an n1-standard-N; the default is n1-standard-4 per GPU. |
provisioning | string | spot | no | spot, flex_start or standard. Not every machine offers every mode (AMICU-CAP-018, for example standard on a3-highgpu-1g). |
max_run_duration | duration | 8h | no | 10m to 2880h (120 days), or 168h (7 days) with flex_start. Write it in s, m or h: days are not accepted. Compute Engine deletes the VM after it. |
idle_shutdown | duration | off | no | Power the VM off after this long without a request (5m or more, shorter than max_run_duration). A watchdog on the VM polls vLLM's /metrics. After it fires the VM is only stopped, not deleted: its boot disk keeps billing and max_run_duration likely no longer applies, until the next amicu apply or amicu destroy deletes it. |
boot_disk_gb | number | 100 | no | At least 50. |
service_account | string | none | yes, unless insecure_metadata_secrets | Email of the account the VM runs as; it reads the VM's secrets from Secret Manager (AMICU-CAP-016 if missing). |
insecure_metadata_secrets | bool | false | no | INSECURE. Deliver the secrets as instance metadata instead of Secret Manager, readable by anyone who can read the instance. |
allowed_source_cidrs | list | this machine's public IP /32 | no | Who may reach the serving port. IPv4 only: an IPv6 CIDR is rejected (AMICU-CAP-016). |
network | string | default | no | Compute Engine only. The VPC network the VM and its firewall rule attach to: a name, projects/<project>/global/networks/<name>, or a full self link (a Shared VPC host project is accepted). Malformed is AMICU-CAP-016; on cloud_run it is AMICU-CAP-019. |
subnetwork | string | none | when network is a custom-mode VPC | Compute Engine only. The subnetwork the VM's interface uses: a name, regions/<region>/subnetworks/<name>, projects/<project>/regions/<region>/subnetworks/<name>, or a full self link. It must be in the VM's region (AMICU-CAP-016 when a link names another region) and needs network. On cloud_run it is AMICU-CAP-019. |
impersonate_service_account | string | none | no | Service account amicu acts as. |
access | string | public | no | Cloud Run only: public (the API key is the only guard) or iam (callers also send a Google identity token). See Cloud Run. |
region is required unless zone is set, so the VM is placed where you expect. The profile's region and the project's data_class residency are checked against every candidate zone. A deployment on a VM runs one replica: scaling {} with more than 1 is rejected (AMICU-CAP-016).
Other checks: an unknown GPU or one not offered in the zone or region is AMICU-CAP-017.
Networks
By default the VM and its firewall rule go on the project's default network. A project without one (for example auto_create_network = false in Terraform) needs network and, because a custom-mode VPC has no automatic subnets, subnetwork:
gcp {
project = "my-project-id"
network = "vpc-main"
subnetwork = "gpu-europe-west4"
}amicu does not pick a subnetwork for you, even when the region has only one: a silent choice would change when someone adds a second subnetwork. If network is custom-mode and subnetwork is missing, apply stops before writing and lists the network's subnetworks in the region.
The VM always gets an external IPv4 address, which is how amicu reaches it. A subnetwork that cannot give one (IPv6-only) is rejected in the preflight, and VMs without an external IP (private-only setups behind Cloud NAT or a VPN) are not supported yet. An organization policy that denies external IPs (constraints/compute.vmExternalIpAccess) makes the VM create fail for the same reason. With a Shared VPC network, the firewall rule is created in the network's (host) project, because a rule belongs to its network's project: the account that runs apply needs compute.firewalls.create there, or a host-project admin must open the serving port for the VM's network tag. A bare subnetwork name is looked up in the network's project. State records the network, so destroy and orphans look for the rule in that project even if the config changes later; records from before this option fall back to the deployment's project.
Projects managed by Terraform
amicu and Terraform can share a project if each manages its own part:
- Terraform manages what amicu only reads or uses: the project, the enabled APIs, the service accounts and their roles, and the network. amicu never enables APIs, creates service accounts or changes IAM; it only reads (preflight) and grants the VM's service account
roles/secretmanager.secretAccessoron the secrets it creates. - amicu manages the VMs, firewall rules, Cloud Run services and Secret Manager secrets it creates, each carrying its owner marker (a label, or a description prefix on firewall rules). Keep those out of Terraform, and do not edit them by hand.
- Set
networkandsubnetworkwhen the project has nodefaultnetwork.
Cloud Run
With backend = "cloud_run", apply creates one Cloud Run service per deployment instead of a VM. Each instance has one GPU: an L4 (at least 4 vCPU, 16 GiB) or an RTX PRO 6000 (at least 20 vCPU, 80 GiB). The profile's memory (and cpu.cores, when set) is used when it is above that minimum; below it is AMICU-CAP-016. The service scales to zero: while no instance runs, nothing is billed for compute. GPU instances are billed for as long as they run, from the moment a request starts one.
Any request can start a billed instance
With the default access = "public", Cloud Run does not filter requests, so any request to the URL, including an anonymous one or a plain GET /health, starts an instance when none is running. That instance is billed while it starts and loads the model (often minutes, the weights are downloaded again on each cold start) and until Cloud Run stops it after it has been idle for a while. The spend is capped by max_replicas instances at a time. Use access = "iam" to let only callers with a Google identity token reach the service.
resource "hardware_profile" "gcp_cloudrun_l4" {
provider = "gcp"
region = "europe-west4"
accelerator {
kind = "gpu"
model = "l4"
count = 1
memory = "24GiB"
}
memory = "16GiB"
gcp {
project = "my-project-id"
backend = "cloud_run"
service_account = "amicu-run@my-project-id.iam.gserviceaccount.com"
}
}A complete example is in examples/gcp-cloudrun-l4.
-
Endpoint and auth. The endpoint is the service's
https://<service>-<hash>.<region>.run.appURL, with Google-managed TLS. Every/v1route needsAuthorization: Bearer <api_key>.access = "public"(default): Cloud Run's IAM invoker check is turned off on this service only (no IAM policy is changed), and the API key is the only guard. After the deploy,applychecks that an anonymous request is refused and the key is accepted. An organization policyconstraints/run.managed.requireInvokerIamforbids this;applythen names the policy and suggestsaccess = "iam".access = "iam": the IAM check stays on. Callers needroles/run.invokeron the service and send a Google identity token for the service URL inX-Serverless-Authorization: Bearer <id token>, plus the API key inAuthorization(for examplecurl -H "X-Serverless-Authorization: Bearer $(gcloud auth print-identity-token)" -H "Authorization: Bearer $CHAT_API_KEY" ...). After the deploy,applychecks that an anonymous request is refused; it holds no identity token, so it does not send the key.
If the check fails,
applydeletes the service and secrets it created. -
Secrets. The API key (and
HF_TOKEN, when set) are stored in Secret Manager in the service's region before the service is created. The service reads them asservice_account, which amicu grantsroles/secretmanager.secretAccessoron those secrets only. -
Write-ahead record. The service and secret names are written to state before anything is created.
destroydeletes the service only if it carries amicu's owner label, waits until a read returns not found, then deletes the secrets. The record leaves state only after that. -
Cold start. The first request after an idle period starts an instance and loads the model. Cloud Run holds the request until the container is ready, which can take minutes, so give clients a long timeout. The startup probe on
/healthallows up to 30 minutes for the model download. -
Scaling.
scaling { max_replicas }is the maximum number of instances (default 1). Each instance holds one GPU, so keep it within the region's Cloud Run GPU quota.target_concurrencyis how many requests one instance serves at once (default 8). Zonal redundancy is off, which is cheaper and needs less quota. -
Regions. L4:
europe-west1,europe-west4,us-central1,us-east4,asia-southeast1(asia-south1by invitation only). RTX PRO 6000:europe-west4,us-central1,asia-southeast1,asia-south2. Another region or GPU isAMICU-CAP-017.
Cloud Run cannot honour some settings, and validate, plan and apply reject them with AMICU-CAP-019: zone, machine_type, provisioning, max_run_duration, idle_shutdown, boot_disk_gb, allowed_source_cidrs, network, subnetwork and insecure_metadata_secrets in the gcp {} block, and min_replicas above 0 or scaledown_window in scaling {}. access is Cloud Run only. accelerator.count must be 1, and service_account and region are required (AMICU-CAP-016).
Before it writes anything, apply checks (read-only) that the Cloud Run Admin API and the Secret Manager API are enabled and that you may act as the service_account, and names the gcloud command or role that fixes each. The account that runs apply needs roles/run.admin (or permission to create, read and delete services), Secret Manager access as above, and roles/iam.serviceAccountUser on the service account. Create the service account as for a VM:
gcloud iam service-accounts create amicu-run --project my-project-idOperations
Before it writes anything, apply on a VM checks (read-only) that the credentials work, that the Secret Manager API is enabled, that the network exists (the project's default, or network), that a custom-mode network comes with a subnetwork that exists, belongs to that network and has IPv4, and that you may act as the service_account. Each failure names the fix, for example gcloud services enable secretmanager.googleapis.com --project <project>, gcloud compute networks subnets create for a missing subnetwork, or granting roles/iam.serviceAccountUser on the service account. amicu never enables APIs or changes IAM itself.
amicu plan and apply compare state with Compute Engine and Cloud Run. A VM that is gone or stopped (a Spot preemption, the max_run_duration backstop, a delete outside amicu), or a Cloud Run service that is gone or whose revision failed, is reported as drift and marked pending: apply recreates it, destroy confirms what is left is removed. A service scaled to zero is not drift. amicu orphans lists VMs, firewall rules, Cloud Run services and Secret Manager secrets in the project that carry amicu's marker but that state does not record, with the gcloud command to delete each. It never deletes anything.
GPUs and regions
| Region code | Location | Jurisdiction |
|---|---|---|
europe-west1 | Belgium | eu |
europe-west4 | Netherlands | eu |
europe-north1 | Finland | eu |
europe-west3 | Frankfurt | eu |
europe-west9 | Paris | eu |
us-central1 | Iowa | us |
us-east1 | South Carolina | us |
asia-east1 | Taiwan | apac |
| Machine type | GPU (accelerator.model) |
|---|---|
a3-highgpu-8g | h100-sxm-80gb |
a2-ultragpu-1g | a100-sxm4-80gb |
g2-standard-8 | l4-24gb |
n1-standard-8 | t4-16gb |
Limits
- The certificate is self-signed and pinned, not CA-signed: clients must pin its fingerprint.
- vLLM only, one VM per deployment, no
envblock, no metrics or logs through amicu. - Cloud Run: one GPU per instance, no minimum instances (always scales to zero), no CIDR allowlist, the idle timeout is Cloud Run's own, and with
access = "iam"amicu cannot check that the API key is accepted. - A4X (
a4x-*, the GB200 and GB300 machines) is not supported yet: amicu has not been tested on its Arm (NVIDIA Grace) boot image and the arm64 vLLM container.applyandplanreject ana4x-*machine_type, and a GB200 or GB300 GPU never picks one by default. - Prices in the catalog are illustrative values, not live quotes, so cost estimates are indicative.
Troubleshooting
Source
Supervisors: crates/amicu-gcp/src/gce.rs (Compute Engine) and crates/amicu-gcp/src/cloudrun/supervisor.rs (Cloud Run). Catalog adapter: crates/amicu-providers/src/gcp.rs. Status of every provider: Providers.
Last updated