GcpCompute.Instance (GcpCompute v0.2.0)

Copy Markdown View Source

A Compute Engine instance — both the parsed result of a get/list, and a builder (spec/1) for the JSON body that insert expects.

Building an insert body

spec/1 turns friendly options into the verbose Compute JSON, with sane defaults for a cheap, self-deleting Spot VM:

{:ok, body} =
  GcpCompute.Instance.spec(
    name: "worker-1",
    zone: "us-central1-a",
    machine_type: "e2-micro",
    spot: true,
    max_run_duration: 3600,
    startup_script: "#!/bin/bash\necho hi > /tmp/ready",
    labels: %{"team" => "platform"}
  )

You can always pass a raw map to GcpCompute.Instances.insert/3 instead if you need a field spec/1 doesn't cover.

Summary

Functions

The instance's first external (NAT) IP address, if any.

Parse a decoded JSON instance map into nested structs (short names, IPs, DateTimes).

The instance's first internal IP address, if any.

Build (and validate) the JSON body for instances.insert.

Same as spec/1 but raises on invalid options.

Types

t()

@type t() :: %GcpCompute.Instance{
  created_at: DateTime.t() | nil,
  disks: [GcpCompute.Disk.t()],
  id: String.t() | nil,
  labels: map() | nil,
  machine_type: String.t() | nil,
  name: String.t() | nil,
  network_interfaces: [GcpCompute.NetworkInterface.t()],
  raw: map(),
  scheduling: GcpCompute.Scheduling.t() | nil,
  self_link: String.t() | nil,
  status: String.t() | nil,
  zone: String.t() | nil
}

Functions

external_ip(instance)

@spec external_ip(t()) :: String.t() | nil

The instance's first external (NAT) IP address, if any.

from_json(map)

@spec from_json(map()) :: t()

Parse a decoded JSON instance map into nested structs (short names, IPs, DateTimes).

internal_ip(instance)

@spec internal_ip(t()) :: String.t() | nil

The instance's first internal IP address, if any.

spec(opts)

@spec spec(keyword()) :: {:ok, map()} | {:error, String.t()}

Build (and validate) the JSON body for instances.insert.

See the module doc for the full option list. Returns {:ok, body} or {:error, message}.

spec!(opts)

@spec spec!(keyword()) :: map()

Same as spec/1 but raises on invalid options.