func (h *Host) RemoveExternalIPs(ctx context.Context, project, zone, instance string) error {
	i, err := h.client.GetInstance(ctx, project, zone, instance)
	if err != nil {
		return fmt.Errorf("failed to get instance: %q", err)
	}
	for _, ni := range i.NetworkInterfaces {
		for _, ac := range ni.AccessConfigs {
			if ac.Type != "ONE_TO_ONE_NAT" {
				continue
			}
			op, err := h.client.DeleteAccessConfig(ctx, project, zone, instance, ac.Name, ni.Name)
			if err != nil {
				return fmt.Errorf("failed to remove external ip: %q", err)
			}
			if errs := h.WaitZone(project, zone, op); len(errs) > 0 {
				return fmt.Errorf("failed to waiting instance. Errors[0]: %s", errs[0])
			}
		}
	}
	return nil
}
RemoveExternalIPs iterates on all network interfaces of an instance and deletes its accessConfigs, actually removing the external IP addresses of the instance.
package services
import (
	"context"
	"fmt"
	"log"
	"strconv"
	"strings"
	"time"
	"github.com/pkg/errors"
	compute "google.golang.org/api/compute/v1"
)
type ComputeClient interface {
	DiskInsert(context.Context, string, string, *compute.Disk) (*compute.Operation, error)
	CreateSnapshot(context.Context, string, string, string, *compute.Snapshot) (*compute.Operation, error)
	DeleteAccessConfig(ctx context.Context, project, zone, instance, accessConfig, networkInterface string) (*compute.Operation, error)
	DeleteDiskSnapshot(context.Context, string, string) (*compute.Operation, error)
	DeleteInstance(context.Context, string, string, string) (*compute.Operation, error)
	GetInstance(ctx context.Context, project, zone, instance string) (*compute.Instance, error)
	ListDisks(context.Context, string, string) (*compute.DiskList, error)
	ListProjectSnapshots(context.Context, string) (*compute.SnapshotList, error)
	SetLabels(context.Context, string, string, *compute.GlobalSetLabelsRequest) (*compute.Operation, error)
	StartInstance(context.Context, string, string, string) (*compute.Operation, error)
	StopInstance(context.Context, string, string, string) (*compute.Operation, error)
	WaitGlobal(string, *compute.Operation) []error
	WaitZone(string, string, *compute.Operation) []error
}
type Host struct {
	client ComputeClient
}
func NewHost(cs ComputeClient) *Host {
	return &Host{client: cs}
}
func (h *Host) DeleteDiskSnapshot(ctx context.Context, projectID, snapshot string) error {
	op, err := h.client.DeleteDiskSnapshot(ctx, projectID, snapshot)
	if err != nil {
		return nil
	}
	if errs := h.WaitGlobal(projectID, op); len(errs) > 0 {
		return errors.Wrap(errs[0], "failed waiting")
	}
	return nil
}