tessl install tessl/golang-cloud-google-com--go--compute@1.53.0Go client library for Google Cloud Compute Engine API providing programmatic access to manage virtual machines, disks, networks, and other compute resources
The cloud.google.com/go/compute/apiv1/computepb package contains 2,669+ protocol buffer types for all Compute API requests, responses, and resources. This document covers the core types and patterns.
import "cloud.google.com/go/compute/apiv1/computepb"All API operations use typed request structs following consistent naming conventions.
Retrieve a single resource by name:
type GetInstanceRequest struct {
Instance string // Resource name
Project string // Project ID
Zone string // Zone name (for zonal resources)
}
type GetDiskRequest struct {
Disk string
Project string
Zone string
}
type GetNetworkRequest struct {
Network string
Project string
// No Zone - global resource
}
type GetRegionDiskRequest struct {
Disk string
Project string
Region string // Region instead of Zone
}List resources with pagination and filtering:
type ListInstancesRequest struct {
Filter *string // Optional filter expression
MaxResults *uint32 // Maximum results per page
OrderBy *string // Sort order
PageToken *string // Pagination token
Project string // Project ID
Zone string // Zone name
}
type ListNetworksRequest struct {
Filter *string
MaxResults *uint32
OrderBy *string
PageToken *string
Project string
// No Zone - global resource
}List resources across all zones or regions:
type AggregatedListInstancesRequest struct {
Filter *string
IncludeAllScopes *bool
MaxResults *uint32
OrderBy *string
PageToken *string
Project string
ReturnPartialSuccess *bool
ServiceProjectNumber *int64
}Create new resources:
type InsertInstanceRequest struct {
InstanceResource *Instance // Resource specification
Project string // Project ID
RequestId *string // Optional idempotency token
SourceInstance *string // Optional source instance
SourceMachineImage *string // Optional source machine image
Zone string // Zone name
}
type InsertDiskRequest struct {
DiskResource *Disk
Project string
RequestId *string
SourceImage *string
Zone string
}Delete resources:
type DeleteInstanceRequest struct {
Instance string
Project string
RequestId *string
Zone string
}
type DeleteDiskRequest struct {
Disk string
Project string
RequestId *string
Zone string
}Full and partial updates:
type UpdateInstanceRequest struct {
Instance string
InstanceResource *Instance
MinimalAction *string
MostDisruptiveAllowedAction *string
Project string
RequestId *string
Zone string
}
type PatchFirewallRequest struct {
Firewall string
FirewallResource *Firewall
Project string
RequestId *string
}Resource-specific operations:
type StartInstanceRequest struct {
Instance string
Project string
RequestId *string
Zone string
}
type StopInstanceRequest struct {
DiscardLocalSsd *bool
Instance string
Project string
RequestId *string
Zone string
}
type AttachDiskInstanceRequest struct {
AttachedDiskResource *AttachedDisk
ForceAttach *bool
Instance string
Project string
RequestId *string
Zone string
}
type ResizeDiskRequest struct {
Disk string
DisksResizeRequestResource *DisksResizeRequest
Project string
RequestId *string
Zone string
}type Instance struct {
AdvancedMachineFeatures *AdvancedMachineFeatures
CanIpForward *bool
ConfidentialInstanceConfig *ConfidentialInstanceConfig
CpuPlatform *string
CreationTimestamp *string
DeletionProtection *bool
Description *string
Disks []*AttachedDisk
DisplayDevice *DisplayDevice
EraseWindowsVssSignature *bool
Fingerprint *string
GuestAccelerators []*AcceleratorConfig
Hostname *string
Id *uint64
InstanceEncryptionKey *CustomerEncryptionKey
KeyRevocationActionType *string
Kind *string
LabelFingerprint *string
Labels map[string]string
LastStartTimestamp *string
LastStopTimestamp *string
LastSuspendedTimestamp *string
MachineType *string
Metadata *Metadata
MinCpuPlatform *string
Name *string
NetworkInterfaces []*NetworkInterface
NetworkPerformanceConfig *NetworkPerformanceConfig
Params *InstanceParams
PrivateIpv6GoogleAccess *string
ReservationAffinity *ReservationAffinity
ResourcePolicies []string
ResourceStatus *ResourceStatus
SatisfiesPzi *bool
SatisfiesPzs *bool
Scheduling *Scheduling
SelfLink *string
ServiceAccounts []*ServiceAccount
ShieldedInstanceConfig *ShieldedInstanceConfig
ShieldedInstanceIntegrityPolicy *ShieldedInstanceIntegrityPolicy
SourceMachineImage *string
SourceMachineImageEncryptionKey *CustomerEncryptionKey
StartRestricted *bool
Status *string
StatusMessage *string
Tags *Tags
Zone *string
}type Disk struct {
AccessMode *string
Architecture *string
AsyncPrimaryDisk *DiskAsyncReplication
AsyncSecondaryDisks map[string]*DiskAsyncReplicationList
CreationTimestamp *string
Description *string
DiskEncryptionKey *CustomerEncryptionKey
EnableConfidentialCompute *bool
EraseWindowsVssSignature *bool
GuestOsFeatures []*GuestOsFeature
Id *uint64
Kind *string
LabelFingerprint *string
Labels map[string]string
LastAttachTimestamp *string
LastDetachTimestamp *string
LicenseCodes []int64
Licenses []string
LocationHint *string
MultiWriter *bool
Name *string
Options *string
Params *DiskParams
PhysicalBlockSizeBytes *int64
ProvisionedIops *int64
ProvisionedThroughput *int64
Region *string
ReplicaZones []string
ResourcePolicies []string
ResourceStatus *DiskResourceStatus
SatisfiesPzi *bool
SatisfiesPzs *bool
SelfLink *string
SizeGb *int64
SourceDisk *string
SourceDiskId *string
SourceImage *string
SourceImageEncryptionKey *CustomerEncryptionKey
SourceImageId *string
SourceInstantSnapshot *string
SourceInstantSnapshotEncryptionKey *CustomerEncryptionKey
SourceInstantSnapshotId *string
SourceSnapshot *string
SourceSnapshotEncryptionKey *CustomerEncryptionKey
SourceSnapshotId *string
SourceStorageObject *string
Status *string
StoragePool *string
StorageType *string
Type *string
Users []string
Zone *string
}type Network struct {
AutoCreateSubnetworks *bool
CreationTimestamp *string
Description *string
EnableUlaInternalIpv6 *bool
FirewallPolicy *string
GatewayIPv4 *string
Id *uint64
InternalIpv6Range *string
Kind *string
Mtu *int32
Name *string
NetworkFirewallPolicyEnforcementOrder *string
Peerings []*NetworkPeering
RoutingConfig *NetworkRoutingConfig
SelfLink *string
Subnetworks []string
}type Subnetwork struct {
CreationTimestamp *string
Description *string
EnableFlowLogs *bool
ExternalIpv6Prefix *string
Fingerprint *string
GatewayAddress *string
Id *uint64
InternalIpv6Prefix *string
IpCidrRange *string
Ipv6AccessType *string
Ipv6CidrRange *string
Kind *string
LogConfig *SubnetworkLogConfig
Name *string
Network *string
PrivateIpGoogleAccess *bool
PrivateIpv6GoogleAccess *string
Purpose *string
Region *string
Role *string
SecondaryIpRanges []*SubnetworkSecondaryRange
SelfLink *string
StackType *string
State *string
}type AttachedDisk struct {
Architecture *string
AutoDelete *bool
Boot *bool
DeviceName *string
DiskEncryptionKey *CustomerEncryptionKey
DiskSizeGb *int64
ForceAttach *bool
GuestOsFeatures []*GuestOsFeature
Index *int32
InitializeParams *AttachedDiskInitializeParams
Interface *string
Kind *string
Licenses []string
Mode *string
SavedState *string
ShieldedInstanceInitialState *InitialStateConfig
Source *string
Type *string
}
type AttachedDiskInitializeParams struct {
Architecture *string
Description *string
DiskName *string
DiskSizeGb *int64
DiskType *string
EnableConfidentialCompute *bool
Labels map[string]string
Licenses []string
MultiWriter *bool
OnUpdateAction *string
ProvisionedIops *int64
ProvisionedThroughput *int64
ReplicaZones []string
ResourceManagerTags map[string]string
ResourcePolicies []string
SourceImage *string
SourceImageEncryptionKey *CustomerEncryptionKey
SourceInstantSnapshot *string
SourceInstantSnapshotEncryptionKey *CustomerEncryptionKey
SourceSnapshot *string
SourceSnapshotEncryptionKey *CustomerEncryptionKey
StoragePool *string
}type NetworkInterface struct {
AccessConfigs []*AccessConfig
AliasIpRanges []*AliasIpRange
Fingerprint *string
InternalIpv6PrefixLength *int32
Ipv6AccessConfigs []*AccessConfig
Ipv6AccessType *string
Ipv6Address *string
Kind *string
Name *string
Network *string
NetworkAttachment *string
NetworkIP *string
NicType *string
QueueCount *int32
SecurityPolicy *string
StackType *string
Subnetwork *string
}
type AccessConfig struct {
ExternalIpv6 *string
ExternalIpv6PrefixLength *int32
Kind *string
Name *string
NatIP *string
NetworkTier *string
PublicPtrDomainName *string
SecurityPolicy *string
SetPublicPtr *bool
Type *string
}type Scheduling struct {
AutomaticRestart *bool
HostErrorTimeoutSeconds *int32
InstanceTerminationAction *string
LocalSsdRecoveryTimeout *SchedulingDuration
LocationHint *string
MaintenanceFreezeDurationHours *int32
MaintenanceInterval *string
MinNodeCpus *int32
NodeAffinities []*SchedulingNodeAffinity
OnHostMaintenance *string
OnInstanceStopAction *SchedulingOnInstanceStopAction
Preemptible *bool
ProvisioningModel *string
TerminationTime *string
}type Metadata struct {
Fingerprint *string
Items []*Items
Kind *string
}
type Items struct {
Key *string
Value *string
}type ServiceAccount struct {
Email *string
Scopes []string
}type Tags struct {
Fingerprint *string
Items []string
}type BackendService struct {
AffinityCookieTtlSec *int32
Backends []*Backend
CdnPolicy *BackendServiceCdnPolicy
CircuitBreakers *CircuitBreakers
CompressionMode *string
ConnectionDraining *ConnectionDraining
ConnectionTrackingPolicy *BackendServiceConnectionTrackingPolicy
ConsistentHash *ConsistentHashLoadBalancerSettings
CreationTimestamp *string
CustomRequestHeaders []string
CustomResponseHeaders []string
Description *string
EdgeSecurityPolicy *string
EnableCDN *bool
FailoverPolicy *BackendServiceFailoverPolicy
Fingerprint *string
HealthChecks []string
Iap *BackendServiceIAP
Id *uint64
Kind *string
LoadBalancingScheme *string
LocalityLbPolicies []*BackendServiceLocalityLoadBalancingPolicyConfig
LocalityLbPolicy *string
LogConfig *BackendServiceLogConfig
MaxStreamDuration *Duration
Metadatas map[string]string
Name *string
Network *string
OutlierDetection *OutlierDetection
Port *int32
PortName *string
Protocol *string
Region *string
SecurityPolicy *string
SecuritySettings *SecuritySettings
SelfLink *string
ServiceBindings []string
ServiceLbPolicy *string
SessionAffinity *string
Subsetting *Subsetting
TimeoutSec *int32
UsedBy []*BackendServiceUsedBy
}
type Backend struct {
BalancingMode *string
CapacityScaler *float64
Description *string
Failover *bool
Group *string
MaxConnections *int32
MaxConnectionsPerEndpoint *int32
MaxConnectionsPerInstance *int32
MaxRate *int32
MaxRatePerEndpoint *float64
MaxRatePerInstance *float64
MaxUtilization *float64
Preference *string
}type HealthCheck struct {
CheckIntervalSec *int32
CreationTimestamp *string
Description *string
GrpcHealthCheck *GRPCHealthCheck
HealthyThreshold *int32
Http2HealthCheck *HTTP2HealthCheck
HttpHealthCheck *HTTPHealthCheck
HttpsHealthCheck *HTTPSHealthCheck
Id *uint64
Kind *string
LogConfig *HealthCheckLogConfig
Name *string
Region *string
SelfLink *string
SourceRegions []string
SslHealthCheck *SSLHealthCheck
TcpHealthCheck *TCPHealthCheck
TimeoutSec *int32
Type *string
UnhealthyThreshold *int32
}
type HTTPHealthCheck struct {
Host *string
Port *int32
PortName *string
PortSpecification *string
ProxyHeader *string
RequestPath *string
Response *string
}type UrlMap struct {
CreationTimestamp *string
DefaultRouteAction *HttpRouteAction
DefaultService *string
DefaultUrlRedirect *HttpRedirectAction
Description *string
Fingerprint *string
HeaderAction *HttpHeaderAction
HostRules []*HostRule
Id *uint64
Kind *string
Name *string
PathMatchers []*PathMatcher
Region *string
SelfLink *string
Tests []*UrlMapTest
}
type PathMatcher struct {
DefaultRouteAction *HttpRouteAction
DefaultService *string
DefaultUrlRedirect *HttpRedirectAction
Description *string
HeaderAction *HttpHeaderAction
Name *string
PathRules []*PathRule
RouteRules []*HttpRouteRule
}
type PathRule struct {
Paths []string
RouteAction *HttpRouteAction
Service *string
UrlRedirect *HttpRedirectAction
}type Firewall struct {
Allowed []*Allowed
CreationTimestamp *string
Denied []*Denied
Description *string
DestinationRanges []string
Direction *string
Disabled *bool
Id *uint64
Kind *string
LogConfig *FirewallLogConfig
Name *string
Network *string
Priority *int32
SelfLink *string
SourceRanges []string
SourceServiceAccounts []string
SourceTags []string
TargetServiceAccounts []string
TargetTags []string
}
type Allowed struct {
IPProtocol *string
Ports []string
}
type Denied struct {
IPProtocol *string
Ports []string
}type SecurityPolicy struct {
AdaptiveProtectionConfig *SecurityPolicyAdaptiveProtectionConfig
AdvancedOptionsConfig *SecurityPolicyAdvancedOptionsConfig
Associations []*SecurityPolicyAssociation
CloudArmorConfig *SecurityPolicyCloudArmorConfig
CreationTimestamp *string
DdosProtectionConfig *SecurityPolicyDdosProtectionConfig
Description *string
Fingerprint *string
Id *uint64
Kind *string
LabelFingerprint *string
Labels map[string]string
Name *string
RecaptchaOptionsConfig *SecurityPolicyRecaptchaOptionsConfig
Region *string
Rules []*SecurityPolicyRule
SelfLink *string
Type *string
}type SslCertificate struct {
Certificate *string
CreationTimestamp *string
Description *string
ExpireTime *string
Id *uint64
Kind *string
Managed *SslCertificateManagedSslCertificate
Name *string
PrivateKey *string
Region *string
SelfLink *string
SelfManaged *SslCertificateSelfManagedSslCertificate
SubjectAlternativeNames []string
Type *string
}Enums are represented as string pointers with specific valid values:
// Valid values for Instance.Status
const (
Instance_PROVISIONING = "PROVISIONING"
Instance_STAGING = "STAGING"
Instance_RUNNING = "RUNNING"
Instance_STOPPING = "STOPPING"
Instance_STOPPED = "STOPPED"
Instance_SUSPENDING = "SUSPENDING"
Instance_SUSPENDED = "SUSPENDED"
Instance_TERMINATED = "TERMINATED"
Instance_REPAIRING = "REPAIRING"
)// Valid values for Disk.Status
const (
Disk_CREATING = "CREATING"
Disk_RESTORING = "RESTORING"
Disk_FAILED = "FAILED"
Disk_READY = "READY"
Disk_DELETING = "DELETING"
)// Valid values for AttachedDisk.Mode
const (
AttachedDisk_READ_WRITE = "READ_WRITE"
AttachedDisk_READ_ONLY = "READ_ONLY"
)// Valid values for AttachedDisk.Type
const (
AttachedDisk_PERSISTENT = "PERSISTENT"
AttachedDisk_SCRATCH = "SCRATCH"
)// Valid values for AccessConfig.NetworkTier
const (
AccessConfig_PREMIUM = "PREMIUM"
AccessConfig_STANDARD = "STANDARD"
)// Valid values for Firewall.Direction
const (
Firewall_INGRESS = "INGRESS"
Firewall_EGRESS = "EGRESS"
)type Policy struct {
AuditConfigs []*AuditConfig
Bindings []*Binding
Etag *string
IamOwned *bool
Rules []*Rule
Version *int32
}
type Binding struct {
BindingId *string
Condition *Expr
Members []string
Role *string
}
type Expr struct {
Description *string
Expression *string
Location *string
Title *string
}All fields in protocol buffer types are pointers to support optional values. Use proto.String(), proto.Int32(), proto.Bool(), etc. from google.golang.org/protobuf/proto:
import "google.golang.org/protobuf/proto"
instance := &computepb.Instance{
Name: proto.String("my-instance"),
MachineType: proto.String("n1-standard-1"),
DeletionProtection: proto.Bool(true),
}Check for nil before dereferencing:
if instance.Name != nil {
fmt.Printf("Name: %s\n", *instance.Name)
}
// Or use helper
name := proto.GetString(instance.Name)Maps are used directly:
instance := &computepb.Instance{
Labels: map[string]string{
"environment": "production",
"team": "backend",
},
}Slices are used directly:
network := &computepb.Network{
Subnetworks: []string{
"projects/my-project/regions/us-central1/subnetworks/subnet1",
"projects/my-project/regions/us-west1/subnetworks/subnet2",
},
}The computepb package includes types for:
See client-specific documentation for request types relevant to each client.