CRUD + lifecycle for Compute Engine instances.
All functions take a GcpCompute.Config and default to its :zone; override
per call with zone: "..." in opts. Mutating calls return a
GcpCompute.Operation; the *_and_wait helpers poll it to completion for you.
{:ok, instance} =
GcpCompute.Instances.insert_and_wait(config,
name: "worker-1",
machine_type: "e2-micro",
spot: true
)
Summary
Functions
Delete an instance. Accepts :zone and :request_id (see insert/3).
Delete an instance and block until the operation is done.
Fetch a single instance by name.
Create an instance. instance is either a keyword spec (built and validated by
GcpCompute.Instance.spec/1) or a raw Compute API body map.
Insert an instance and block until it exists, returning the live
GcpCompute.Instance.
List instances in a zone (single page).
List one page of instances, surfacing the pagination token.
Start a stopped instance.
Stop a running instance.
Types
Functions
@spec delete(GcpCompute.Config.t(), String.t(), keyword()) :: {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}
Delete an instance. Accepts :zone and :request_id (see insert/3).
@spec delete_and_wait(GcpCompute.Config.t(), String.t(), keyword()) :: {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}
Delete an instance and block until the operation is done.
@spec get(GcpCompute.Config.t(), String.t(), keyword()) :: {:ok, GcpCompute.Instance.t()} | {:error, GcpCompute.Error.t()}
Fetch a single instance by name.
@spec insert(GcpCompute.Config.t(), spec(), keyword()) :: {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}
Create an instance. instance is either a keyword spec (built and validated by
GcpCompute.Instance.spec/1) or a raw Compute API body map.
Options
:zone— override the config's default zone.:request_id— idempotency token (requestId); safe to retry.
@spec insert_and_wait(GcpCompute.Config.t(), spec(), keyword()) :: {:ok, GcpCompute.Instance.t()} | {:error, GcpCompute.Error.t()}
Insert an instance and block until it exists, returning the live
GcpCompute.Instance.
Accepts every insert/3 option plus :timeout (ms) for the operation poll.
@spec list( GcpCompute.Config.t(), keyword() ) :: {:ok, [GcpCompute.Instance.t()]} | {:error, GcpCompute.Error.t()}
List instances in a zone (single page).
Returns just the items; callers that need to paginate should use list_page/2,
which also surfaces the nextPageToken.
Options
:zone,:filter,:maxResults,:pageToken,:orderBy— passed through to the Compute API.
@spec list_page( GcpCompute.Config.t(), keyword() ) :: {:ok, %{items: [GcpCompute.Instance.t()], next_page_token: String.t() | nil}} | {:error, GcpCompute.Error.t()}
List one page of instances, surfacing the pagination token.
Same options as list/2. Returns {:ok, %{items: [Instance.t()], next_page_token: String.t() | nil}}; next_page_token is nil on the last
(or only) page — pass it back as :pageToken to fetch the next page.
@spec start(GcpCompute.Config.t(), String.t(), keyword()) :: {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}
Start a stopped instance.
@spec stop(GcpCompute.Config.t(), String.t(), keyword()) :: {:ok, GcpCompute.Operation.t()} | {:error, GcpCompute.Error.t()}
Stop a running instance.