googlecompute

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2020 License: MPL-2.0 Imports: 35 Imported by: 0

Documentation

Overview

The googlecompute package contains a packer.Builder implementation that builds images for Google Compute Engine.

Code generated by "mapstructure-to-hcl2 -type Config,CustomerEncryptionKey"; DO NOT EDIT.

Index

Constants

View Source
const BuilderId = "packer.googlecompute"

The unique ID for this builder.

View Source
const StartupScriptKey string = "startup-script"
View Source
const StartupScriptStatusDone string = "done"
View Source
const StartupScriptStatusError string = "error"
View Source
const StartupScriptStatusKey string = "startup-script-status"
View Source
const StartupScriptStatusNotDone string = "notdone"
View Source
const StartupWrappedScriptKey string = "packer-wrapped-startup-script"

Variables

View Source
var DriverScopes = []string{"https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.full_control"}
View Source
var StartupScriptLinux string = fmt.Sprintf(`#!/usr/bin/env bash
echo "Packer startup script starting."
RETVAL=0
BASEMETADATAURL=http://metadata.google.internal/computeMetadata/v1/instance/

GetMetadata () {
  echo "$(curl -f -H "Metadata-Flavor: Google" ${BASEMETADATAURL}/${1} 2> /dev/null)"
}

ZONE=$(basename $(GetMetadata zone))

SetMetadata () {
  gcloud compute instances add-metadata ${HOSTNAME} --metadata ${1}=${2} --zone ${ZONE}
}

STARTUPSCRIPT=$(GetMetadata attributes/%s)
STARTUPSCRIPTPATH=/packer-wrapped-startup-script
if [ -f "/var/log/startupscript.log" ]; then
  STARTUPSCRIPTLOGPATH=/var/log/startupscript.log
else
  STARTUPSCRIPTLOGPATH=/var/log/daemon.log
fi
STARTUPSCRIPTLOGDEST=$(GetMetadata attributes/startup-script-log-dest)

if [[ ! -z $STARTUPSCRIPT ]]; then
  echo "Executing user-provided startup script..."
  echo "${STARTUPSCRIPT}" > ${STARTUPSCRIPTPATH}
  chmod +x ${STARTUPSCRIPTPATH}
  ${STARTUPSCRIPTPATH}
  RETVAL=$?

  if [[ ! -z $STARTUPSCRIPTLOGDEST ]]; then
    echo "Uploading user-provided startup script log to ${STARTUPSCRIPTLOGDEST}..."
    gsutil -h "Content-Type:text/plain" cp ${STARTUPSCRIPTLOGPATH} ${STARTUPSCRIPTLOGDEST}
  fi

  rm ${STARTUPSCRIPTPATH}
fi

echo "Packer startup script done."
SetMetadata %s %s
exit $RETVAL
`, StartupWrappedScriptKey, StartupScriptStatusKey, StartupScriptStatusDone)
View Source
var StartupScriptWindows string = ""
View Source
var TemplateFuncs = template.FuncMap{
	"clean_resource_name": templateCleanImageName,
}

Functions

func NewClientGCE added in v1.3.5

func NewClientGCE(conf *jwt.Config, vaultOauth string) (*http.Client, error)

func ProcessAccountFile added in v0.11.0

func ProcessAccountFile(text string) (*jwt.Config, error)

Types

type Artifact

type Artifact struct {

	// StateData should store data such as GeneratedData
	// to be shared with post-processors
	StateData map[string]interface{}
	// contains filtered or unexported fields
}

Artifact represents a GCE image as the result of a Packer build.

func (*Artifact) BuilderId

func (*Artifact) BuilderId() string

BuilderId returns the builder Id.

func (*Artifact) Destroy

func (a *Artifact) Destroy() error

Destroy destroys the GCE image represented by the artifact.

func (*Artifact) Files

func (*Artifact) Files() []string

Files returns the files represented by the artifact.

func (*Artifact) Id

func (a *Artifact) Id() string

Id returns the GCE image name.

func (*Artifact) State added in v0.7.2

func (a *Artifact) State(name string) interface{}

func (*Artifact) String

func (a *Artifact) String() string

String returns the string representation of the artifact.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder represents a Packer Builder.

func (*Builder) ConfigSpec added in v1.5.0

func (b *Builder) ConfigSpec() hcldec.ObjectSpec

func (*Builder) Prepare

func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error)

func (*Builder) Run

func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error)

Run executes a googlecompute Packer build and returns a packer.Artifact representing a GCE machine image.

type Config

type Config struct {
	common.PackerConfig `mapstructure:",squash"`
	Comm                communicator.Config `mapstructure:",squash"`

	// The JSON file containing your account credentials. Not required if you
	// run Packer on a GCE instance with a service account. Instructions for
	// creating the file or using service accounts are above.
	AccountFile string `mapstructure:"account_file" required:"false"`
	// The project ID that will be used to launch instances and store images.
	ProjectId string `mapstructure:"project_id" required:"true"`
	// Full or partial URL of the guest accelerator type. GPU accelerators can
	// only be used with `"on_host_maintenance": "TERMINATE"` option set.
	// Example:
	// `"projects/project_id/zones/europe-west1-b/acceleratorTypes/nvidia-tesla-k80"`
	AcceleratorType string `mapstructure:"accelerator_type" required:"false"`
	// Number of guest accelerator cards to add to the launched instance.
	AcceleratorCount int64 `mapstructure:"accelerator_count" required:"false"`
	// The name of a pre-allocated static external IP address. Note, must be
	// the name and not the actual IP address.
	Address string `mapstructure:"address" required:"false"`
	// If true, the default service account will not be used if
	// service_account_email is not specified. Set this value to true and omit
	// service_account_email to provision a VM with no service account.
	DisableDefaultServiceAccount bool `mapstructure:"disable_default_service_account" required:"false"`
	// The name of the disk, if unset the instance name will be used.
	DiskName string `mapstructure:"disk_name" required:"false"`
	// The size of the disk in GB. This defaults to 10, which is 10GB.
	DiskSizeGb int64 `mapstructure:"disk_size" required:"false"`
	// Type of disk used to back your instance, like pd-ssd or pd-standard.
	// Defaults to pd-standard.
	DiskType string `mapstructure:"disk_type" required:"false"`
	// The unique name of the resulting image. Defaults to
	// "packer-{{timestamp}}".
	ImageName string `mapstructure:"image_name" required:"false"`
	// The description of the resulting image.
	ImageDescription string `mapstructure:"image_description" required:"false"`
	// Image encryption key to apply to the created image. Possible values:
	// * kmsKeyName -  The name of the encryption key that is stored in Google Cloud KMS.
	// * RawKey: - A 256-bit customer-supplied encryption key, encodes in RFC 4648 base64.
	//
	// example:
	//
	//  “` json
	//  {
	//     "kmsKeyName": "projects/${project}/locations/${region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
	//  }
	//  “`
	ImageEncryptionKey *CustomerEncryptionKey `mapstructure:"image_encryption_key" required:"false"`
	// The name of the image family to which the resulting image belongs. You
	// can create disks by specifying an image family instead of a specific
	// image name. The image family always returns its latest image that is not
	// deprecated.
	ImageFamily string `mapstructure:"image_family" required:"false"`
	// Key/value pair labels to apply to the created image.
	ImageLabels map[string]string `mapstructure:"image_labels" required:"false"`
	// Licenses to apply to the created image.
	ImageLicenses []string `mapstructure:"image_licenses" required:"false"`
	// A name to give the launched instance. Beware that this must be unique.
	// Defaults to "packer-{{uuid}}".
	InstanceName string `mapstructure:"instance_name" required:"false"`
	// Key/value pair labels to apply to the launched instance.
	Labels map[string]string `mapstructure:"labels" required:"false"`
	// The machine type. Defaults to "n1-standard-1".
	MachineType string `mapstructure:"machine_type" required:"false"`
	// Metadata applied to the launched instance.
	Metadata map[string]string `mapstructure:"metadata" required:"false"`
	// Metadata applied to the launched instance. Values are files.
	MetadataFiles map[string]string `mapstructure:"metadata_files"`
	// A Minimum CPU Platform for VM Instance. Availability and default CPU
	// platforms vary across zones, based on the hardware available in each GCP
	// zone.
	// [Details](https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform)
	MinCpuPlatform string `mapstructure:"min_cpu_platform" required:"false"`
	// The Google Compute network id or URL to use for the launched instance.
	// Defaults to "default". If the value is not a URL, it will be
	// interpolated to
	// projects/((network_project_id))/global/networks/((network)). This value
	// is not required if a subnet is specified.
	Network string `mapstructure:"network" required:"false"`
	// The project ID for the network and subnetwork to use for launched
	// instance. Defaults to project_id.
	NetworkProjectId string `mapstructure:"network_project_id" required:"false"`
	// If true, the instance will not have an external IP. use_internal_ip must
	// be true if this property is true.
	OmitExternalIP bool `mapstructure:"omit_external_ip" required:"false"`
	// Sets Host Maintenance Option. Valid choices are `MIGRATE` and
	// `TERMINATE`. Please see [GCE Instance Scheduling
	// Options](https://cloud.google.com/compute/docs/instances/setting-instance-scheduling-options),
	// as not all machine\_types support `MIGRATE` (i.e. machines with GPUs).
	// If preemptible is true this can only be `TERMINATE`. If preemptible is
	// false, it defaults to `MIGRATE`
	OnHostMaintenance string `mapstructure:"on_host_maintenance" required:"false"`
	// If true, launch a preemptible instance.
	Preemptible bool `mapstructure:"preemptible" required:"false"`
	// The time to wait for instance state changes. Defaults to "5m".
	StateTimeout time.Duration `mapstructure:"state_timeout" required:"false"`
	// The region in which to launch the instance. Defaults to the region
	// hosting the specified zone.
	Region string `mapstructure:"region" required:"false"`
	// The service account scopes for launched
	// instance. Defaults to:
	//
	// “` json
	// [
	//   "https://www.googleapis.com/auth/userinfo.email",
	//   "https://www.googleapis.com/auth/compute",
	//   "https://www.googleapis.com/auth/devstorage.full_control"
	// ]
	// “`
	Scopes []string `mapstructure:"scopes" required:"false"`
	// The service account to be used for launched instance. Defaults to the
	// project's default service account unless disable_default_service_account
	// is true.
	ServiceAccountEmail string `mapstructure:"service_account_email" required:"false"`
	// The source image to use to create the new image from. You can also
	// specify source_image_family instead. If both source_image and
	// source_image_family are specified, source_image takes precedence.
	// Example: "debian-8-jessie-v20161027"
	SourceImage string `mapstructure:"source_image" required:"true"`
	// The source image family to use to create the new image from. The image
	// family always returns its latest image that is not deprecated. Example:
	// "debian-8".
	SourceImageFamily string `mapstructure:"source_image_family" required:"true"`
	// The project ID of the project containing the source image.
	SourceImageProjectId string `mapstructure:"source_image_project_id" required:"false"`
	// The path to a startup script to run on the VM from which the image will
	// be made.
	StartupScriptFile string `mapstructure:"startup_script_file" required:"false"`
	// The Google Compute subnetwork id or URL to use for the launched
	// instance. Only required if the network has been created with custom
	// subnetting. Note, the region of the subnetwork must match the region or
	// zone in which the VM is launched. If the value is not a URL, it will be
	// interpolated to
	// projects/((network_project_id))/regions/((region))/subnetworks/((subnetwork))
	Subnetwork string `mapstructure:"subnetwork" required:"false"`
	// Assign network tags to apply firewall rules to VM instance.
	Tags []string `mapstructure:"tags" required:"false"`
	// If true, use the instance's internal IP instead of its external IP
	// during building.
	UseInternalIP bool `mapstructure:"use_internal_ip" required:"false"`
	// Can be set instead of account_file. If set, this builder will use
	// HashiCorp Vault to generate an Oauth token for authenticating against
	// Google's cloud. The value should be the path of the token generator
	// within vault.
	// For information on how to configure your Vault + GCP engine to produce
	// Oauth tokens, see https://www.vaultproject.io/docs/auth/gcp.html
	// You must have the environment variables VAULT_ADDR and VAULT_TOKEN set,
	// along with any other relevant variables for accessing your vault
	// instance. For more information, see the Vault docs:
	// https://www.vaultproject.io/docs/commands/#environment-variables
	// Example:`"vault_gcp_oauth_engine": "gcp/token/my-project-editor",`
	VaultGCPOauthEngine string `mapstructure:"vault_gcp_oauth_engine"`
	// The zone in which to launch the instance used to create the image.
	// Example: "us-central1-a"
	Zone string `mapstructure:"zone" required:"true"`
	// contains filtered or unexported fields
}

Config is the configuration structure for the GCE builder. It stores both the publicly settable state as well as the privately generated state of the config object.

func (*Config) FlatMapstructure added in v1.4.5

func (*Config) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }

FlatMapstructure returns a new FlatConfig. FlatConfig is an auto-generated flat version of Config. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.

func (*Config) Prepare added in v1.5.0

func (c *Config) Prepare(raws ...interface{}) ([]string, error)

type CustomerEncryptionKey added in v1.4.5

type CustomerEncryptionKey struct {
	// KmsKeyName: The name of the encryption key that is stored in Google
	// Cloud KMS.
	KmsKeyName string `json:"kmsKeyName,omitempty"`

	// RawKey: Specifies a 256-bit customer-supplied encryption key, encoded
	// in RFC 4648 base64 to either encrypt or decrypt this resource.
	RawKey string `json:"rawKey,omitempty"`
}

func (*CustomerEncryptionKey) ComputeType added in v1.4.5

func (*CustomerEncryptionKey) FlatMapstructure added in v1.4.5

func (*CustomerEncryptionKey) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }

FlatMapstructure returns a new FlatCustomerEncryptionKey. FlatCustomerEncryptionKey is an auto-generated flat version of CustomerEncryptionKey. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.

type Driver

type Driver interface {
	// CreateImage creates an image from the given disk in Google Compute
	// Engine.
	CreateImage(name, description, family, zone, disk string, image_labels map[string]string, image_licenses []string, image_encryption_key *compute.CustomerEncryptionKey) (<-chan *Image, <-chan error)

	// DeleteImage deletes the image with the given name.
	DeleteImage(name string) <-chan error

	// DeleteInstance deletes the given instance, keeping the boot disk.
	DeleteInstance(zone, name string) (<-chan error, error)

	// DeleteDisk deletes the disk with the given name.
	DeleteDisk(zone, name string) (<-chan error, error)

	// GetImage gets an image; tries the default and public projects. If
	// fromFamily is true, name designates an image family instead of a
	// particular image.
	GetImage(name string, fromFamily bool) (*Image, error)

	// GetImageFromProject gets an image from a specific project. If fromFamily
	// is true, name designates an image family instead of a particular image.
	GetImageFromProject(project, name string, fromFamily bool) (*Image, error)

	// GetInstanceMetadata gets a metadata variable for the instance, name.
	GetInstanceMetadata(zone, name, key string) (string, error)

	// GetInternalIP gets the GCE-internal IP address for the instance.
	GetInternalIP(zone, name string) (string, error)

	// GetNatIP gets the NAT IP address for the instance.
	GetNatIP(zone, name string) (string, error)

	// GetSerialPortOutput gets the Serial Port contents for the instance.
	GetSerialPortOutput(zone, name string) (string, error)

	// ImageExists returns true if the specified image exists. If an error
	// occurs calling the API, this method returns false.
	ImageExists(name string) bool

	// RunInstance takes the given config and launches an instance.
	RunInstance(*InstanceConfig) (<-chan error, error)

	// WaitForInstance waits for an instance to reach the given state.
	WaitForInstance(state, zone, name string) <-chan error

	// CreateOrResetWindowsPassword creates or resets the password for a user on an Windows instance.
	CreateOrResetWindowsPassword(zone, name string, config *WindowsPasswordConfig) (<-chan error, error)
}

Driver is the interface that has to be implemented to communicate with GCE. The Driver interface exists mostly to allow a mock implementation to be used to test the steps.

func NewDriverGCE

func NewDriverGCE(ui packer.Ui, p string, conf *jwt.Config, vaultOauth string) (Driver, error)

type DriverMock

type DriverMock struct {
	CreateImageName            string
	CreateImageDesc            string
	CreateImageFamily          string
	CreateImageEncryptionKey   *compute.CustomerEncryptionKey
	CreateImageLabels          map[string]string
	CreateImageLicenses        []string
	CreateImageZone            string
	CreateImageDisk            string
	CreateImageResultProjectId string
	CreateImageResultSelfLink  string
	CreateImageResultSizeGb    int64
	CreateImageErrCh           <-chan error
	CreateImageResultCh        <-chan *Image

	DeleteImageName  string
	DeleteImageErrCh <-chan error

	DeleteInstanceZone  string
	DeleteInstanceName  string
	DeleteInstanceErrCh <-chan error
	DeleteInstanceErr   error

	DeleteDiskZone  string
	DeleteDiskName  string
	DeleteDiskErrCh <-chan error
	DeleteDiskErr   error

	GetImageName       string
	GetImageFromFamily bool
	GetImageResult     *Image
	GetImageErr        error

	GetImageFromProjectProject    string
	GetImageFromProjectName       string
	GetImageFromProjectFromFamily bool
	GetImageFromProjectResult     *Image
	GetImageFromProjectErr        error

	GetInstanceMetadataZone   string
	GetInstanceMetadataName   string
	GetInstanceMetadataKey    string
	GetInstanceMetadataResult string
	GetInstanceMetadataErr    error

	GetNatIPZone   string
	GetNatIPName   string
	GetNatIPResult string
	GetNatIPErr    error

	GetInternalIPZone   string
	GetInternalIPName   string
	GetInternalIPResult string
	GetInternalIPErr    error

	GetSerialPortOutputZone   string
	GetSerialPortOutputName   string
	GetSerialPortOutputResult string
	GetSerialPortOutputErr    error

	ImageExistsName   string
	ImageExistsResult bool

	RunInstanceConfig *InstanceConfig
	RunInstanceErrCh  <-chan error
	RunInstanceErr    error

	CreateOrResetWindowsPasswordZone     string
	CreateOrResetWindowsPasswordInstance string
	CreateOrResetWindowsPasswordConfig   *WindowsPasswordConfig
	CreateOrResetWindowsPasswordErr      error
	CreateOrResetWindowsPasswordErrCh    <-chan error

	WaitForInstanceState string
	WaitForInstanceZone  string
	WaitForInstanceName  string
	WaitForInstanceErrCh <-chan error
}

DriverMock is a Driver implementation that is a mocked out so that it can be used for tests.

func (*DriverMock) CreateImage

func (d *DriverMock) CreateImage(name, description, family, zone, disk string, image_labels map[string]string, image_licenses []string, image_encryption_key *compute.CustomerEncryptionKey) (<-chan *Image, <-chan error)

func (*DriverMock) CreateOrResetWindowsPassword added in v0.11.0

func (d *DriverMock) CreateOrResetWindowsPassword(instance, zone string, c *WindowsPasswordConfig) (<-chan error, error)

func (*DriverMock) DeleteDisk added in v0.7.5

func (d *DriverMock) DeleteDisk(zone, name string) (<-chan error, error)

func (*DriverMock) DeleteImage

func (d *DriverMock) DeleteImage(name string) <-chan error

func (*DriverMock) DeleteInstance

func (d *DriverMock) DeleteInstance(zone, name string) (<-chan error, error)

func (*DriverMock) GetImage added in v0.11.0

func (d *DriverMock) GetImage(name string, fromFamily bool) (*Image, error)

func (*DriverMock) GetImageFromProject added in v0.11.0

func (d *DriverMock) GetImageFromProject(project, name string, fromFamily bool) (*Image, error)

func (*DriverMock) GetInstanceMetadata added in v0.11.0

func (d *DriverMock) GetInstanceMetadata(zone, name, key string) (string, error)

func (*DriverMock) GetInternalIP added in v0.8.0

func (d *DriverMock) GetInternalIP(zone, name string) (string, error)

func (*DriverMock) GetNatIP

func (d *DriverMock) GetNatIP(zone, name string) (string, error)

func (*DriverMock) GetSerialPortOutput added in v0.11.0

func (d *DriverMock) GetSerialPortOutput(zone, name string) (string, error)

func (*DriverMock) GetWindowsPassword added in v0.11.0

func (d *DriverMock) GetWindowsPassword() (string, error)

func (*DriverMock) ImageExists added in v0.7.5

func (d *DriverMock) ImageExists(name string) bool

func (*DriverMock) RunInstance

func (d *DriverMock) RunInstance(c *InstanceConfig) (<-chan error, error)

func (*DriverMock) WaitForInstance

func (d *DriverMock) WaitForInstance(state, zone, name string) <-chan error

type FlatConfig added in v1.4.5

type FlatConfig struct {
	PackerBuildName              *string                    `mapstructure:"packer_build_name" cty:"packer_build_name"`
	PackerBuilderType            *string                    `mapstructure:"packer_builder_type" cty:"packer_builder_type"`
	PackerDebug                  *bool                      `mapstructure:"packer_debug" cty:"packer_debug"`
	PackerForce                  *bool                      `mapstructure:"packer_force" cty:"packer_force"`
	PackerOnError                *string                    `mapstructure:"packer_on_error" cty:"packer_on_error"`
	PackerUserVars               map[string]string          `mapstructure:"packer_user_variables" cty:"packer_user_variables"`
	PackerSensitiveVars          []string                   `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables"`
	Type                         *string                    `mapstructure:"communicator" cty:"communicator"`
	PauseBeforeConnect           *string                    `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"`
	SSHHost                      *string                    `mapstructure:"ssh_host" cty:"ssh_host"`
	SSHPort                      *int                       `mapstructure:"ssh_port" cty:"ssh_port"`
	SSHUsername                  *string                    `mapstructure:"ssh_username" cty:"ssh_username"`
	SSHPassword                  *string                    `mapstructure:"ssh_password" cty:"ssh_password"`
	SSHKeyPairName               *string                    `mapstructure:"ssh_keypair_name" cty:"ssh_keypair_name"`
	SSHTemporaryKeyPairName      *string                    `mapstructure:"temporary_key_pair_name" cty:"temporary_key_pair_name"`
	SSHClearAuthorizedKeys       *bool                      `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys"`
	SSHPrivateKeyFile            *string                    `mapstructure:"ssh_private_key_file" cty:"ssh_private_key_file"`
	SSHPty                       *bool                      `mapstructure:"ssh_pty" cty:"ssh_pty"`
	SSHTimeout                   *string                    `mapstructure:"ssh_timeout" cty:"ssh_timeout"`
	SSHAgentAuth                 *bool                      `mapstructure:"ssh_agent_auth" cty:"ssh_agent_auth"`
	SSHDisableAgentForwarding    *bool                      `mapstructure:"ssh_disable_agent_forwarding" cty:"ssh_disable_agent_forwarding"`
	SSHHandshakeAttempts         *int                       `mapstructure:"ssh_handshake_attempts" cty:"ssh_handshake_attempts"`
	SSHBastionHost               *string                    `mapstructure:"ssh_bastion_host" cty:"ssh_bastion_host"`
	SSHBastionPort               *int                       `mapstructure:"ssh_bastion_port" cty:"ssh_bastion_port"`
	SSHBastionAgentAuth          *bool                      `mapstructure:"ssh_bastion_agent_auth" cty:"ssh_bastion_agent_auth"`
	SSHBastionUsername           *string                    `mapstructure:"ssh_bastion_username" cty:"ssh_bastion_username"`
	SSHBastionPassword           *string                    `mapstructure:"ssh_bastion_password" cty:"ssh_bastion_password"`
	SSHBastionPrivateKeyFile     *string                    `mapstructure:"ssh_bastion_private_key_file" cty:"ssh_bastion_private_key_file"`
	SSHFileTransferMethod        *string                    `mapstructure:"ssh_file_transfer_method" cty:"ssh_file_transfer_method"`
	SSHProxyHost                 *string                    `mapstructure:"ssh_proxy_host" cty:"ssh_proxy_host"`
	SSHProxyPort                 *int                       `mapstructure:"ssh_proxy_port" cty:"ssh_proxy_port"`
	SSHProxyUsername             *string                    `mapstructure:"ssh_proxy_username" cty:"ssh_proxy_username"`
	SSHProxyPassword             *string                    `mapstructure:"ssh_proxy_password" cty:"ssh_proxy_password"`
	SSHKeepAliveInterval         *string                    `mapstructure:"ssh_keep_alive_interval" cty:"ssh_keep_alive_interval"`
	SSHReadWriteTimeout          *string                    `mapstructure:"ssh_read_write_timeout" cty:"ssh_read_write_timeout"`
	SSHRemoteTunnels             []string                   `mapstructure:"ssh_remote_tunnels" cty:"ssh_remote_tunnels"`
	SSHLocalTunnels              []string                   `mapstructure:"ssh_local_tunnels" cty:"ssh_local_tunnels"`
	SSHPublicKey                 []byte                     `mapstructure:"ssh_public_key" cty:"ssh_public_key"`
	SSHPrivateKey                []byte                     `mapstructure:"ssh_private_key" cty:"ssh_private_key"`
	WinRMUser                    *string                    `mapstructure:"winrm_username" cty:"winrm_username"`
	WinRMPassword                *string                    `mapstructure:"winrm_password" cty:"winrm_password"`
	WinRMHost                    *string                    `mapstructure:"winrm_host" cty:"winrm_host"`
	WinRMPort                    *int                       `mapstructure:"winrm_port" cty:"winrm_port"`
	WinRMTimeout                 *string                    `mapstructure:"winrm_timeout" cty:"winrm_timeout"`
	WinRMUseSSL                  *bool                      `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl"`
	WinRMInsecure                *bool                      `mapstructure:"winrm_insecure" cty:"winrm_insecure"`
	WinRMUseNTLM                 *bool                      `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"`
	AccountFile                  *string                    `mapstructure:"account_file" required:"false" cty:"account_file"`
	ProjectId                    *string                    `mapstructure:"project_id" required:"true" cty:"project_id"`
	AcceleratorType              *string                    `mapstructure:"accelerator_type" required:"false" cty:"accelerator_type"`
	AcceleratorCount             *int64                     `mapstructure:"accelerator_count" required:"false" cty:"accelerator_count"`
	Address                      *string                    `mapstructure:"address" required:"false" cty:"address"`
	DisableDefaultServiceAccount *bool                      `mapstructure:"disable_default_service_account" required:"false" cty:"disable_default_service_account"`
	DiskName                     *string                    `mapstructure:"disk_name" required:"false" cty:"disk_name"`
	DiskSizeGb                   *int64                     `mapstructure:"disk_size" required:"false" cty:"disk_size"`
	DiskType                     *string                    `mapstructure:"disk_type" required:"false" cty:"disk_type"`
	ImageName                    *string                    `mapstructure:"image_name" required:"false" cty:"image_name"`
	ImageDescription             *string                    `mapstructure:"image_description" required:"false" cty:"image_description"`
	ImageEncryptionKey           *FlatCustomerEncryptionKey `mapstructure:"image_encryption_key" required:"false" cty:"image_encryption_key"`
	ImageFamily                  *string                    `mapstructure:"image_family" required:"false" cty:"image_family"`
	ImageLabels                  map[string]string          `mapstructure:"image_labels" required:"false" cty:"image_labels"`
	ImageLicenses                []string                   `mapstructure:"image_licenses" required:"false" cty:"image_licenses"`
	InstanceName                 *string                    `mapstructure:"instance_name" required:"false" cty:"instance_name"`
	Labels                       map[string]string          `mapstructure:"labels" required:"false" cty:"labels"`
	MachineType                  *string                    `mapstructure:"machine_type" required:"false" cty:"machine_type"`
	Metadata                     map[string]string          `mapstructure:"metadata" required:"false" cty:"metadata"`
	MetadataFiles                map[string]string          `mapstructure:"metadata_files" cty:"metadata_files"`
	MinCpuPlatform               *string                    `mapstructure:"min_cpu_platform" required:"false" cty:"min_cpu_platform"`
	Network                      *string                    `mapstructure:"network" required:"false" cty:"network"`
	NetworkProjectId             *string                    `mapstructure:"network_project_id" required:"false" cty:"network_project_id"`
	OmitExternalIP               *bool                      `mapstructure:"omit_external_ip" required:"false" cty:"omit_external_ip"`
	OnHostMaintenance            *string                    `mapstructure:"on_host_maintenance" required:"false" cty:"on_host_maintenance"`
	Preemptible                  *bool                      `mapstructure:"preemptible" required:"false" cty:"preemptible"`
	StateTimeout                 *string                    `mapstructure:"state_timeout" required:"false" cty:"state_timeout"`
	Region                       *string                    `mapstructure:"region" required:"false" cty:"region"`
	Scopes                       []string                   `mapstructure:"scopes" required:"false" cty:"scopes"`
	ServiceAccountEmail          *string                    `mapstructure:"service_account_email" required:"false" cty:"service_account_email"`
	SourceImage                  *string                    `mapstructure:"source_image" required:"true" cty:"source_image"`
	SourceImageFamily            *string                    `mapstructure:"source_image_family" required:"true" cty:"source_image_family"`
	SourceImageProjectId         *string                    `mapstructure:"source_image_project_id" required:"false" cty:"source_image_project_id"`
	StartupScriptFile            *string                    `mapstructure:"startup_script_file" required:"false" cty:"startup_script_file"`
	Subnetwork                   *string                    `mapstructure:"subnetwork" required:"false" cty:"subnetwork"`
	Tags                         []string                   `mapstructure:"tags" required:"false" cty:"tags"`
	UseInternalIP                *bool                      `mapstructure:"use_internal_ip" required:"false" cty:"use_internal_ip"`
	VaultGCPOauthEngine          *string                    `mapstructure:"vault_gcp_oauth_engine" cty:"vault_gcp_oauth_engine"`
	Zone                         *string                    `mapstructure:"zone" required:"true" cty:"zone"`
}

FlatConfig is an auto-generated flat version of Config. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.

func (*FlatConfig) HCL2Spec added in v1.4.5

func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec

HCL2Spec returns the hcl spec of a Config. This spec is used by HCL to read the fields of Config. The decoded values from this spec will then be applied to a FlatConfig.

type FlatCustomerEncryptionKey added in v1.4.5

type FlatCustomerEncryptionKey struct {
	KmsKeyName *string `json:"kmsKeyName,omitempty" cty:"kms_key_name"`
	RawKey     *string `json:"rawKey,omitempty" cty:"raw_key"`
}

FlatCustomerEncryptionKey is an auto-generated flat version of CustomerEncryptionKey. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.

func (*FlatCustomerEncryptionKey) HCL2Spec added in v1.4.5

func (*FlatCustomerEncryptionKey) HCL2Spec() map[string]hcldec.Spec

HCL2Spec returns the hcl spec of a CustomerEncryptionKey. This spec is used by HCL to read the fields of CustomerEncryptionKey. The decoded values from this spec will then be applied to a FlatCustomerEncryptionKey.

type Image added in v0.7.0

type Image struct {
	Labels    map[string]string
	Licenses  []string
	Name      string
	ProjectId string
	SelfLink  string
	SizeGb    int64
}

func (*Image) IsWindows added in v0.11.0

func (i *Image) IsWindows() bool

type InstanceConfig

type InstanceConfig struct {
	AcceleratorType              string
	AcceleratorCount             int64
	Address                      string
	Description                  string
	DisableDefaultServiceAccount bool
	DiskSizeGb                   int64
	DiskType                     string
	Image                        *Image
	Labels                       map[string]string
	MachineType                  string
	Metadata                     map[string]string
	MinCpuPlatform               string
	Name                         string
	Network                      string
	NetworkProjectId             string
	OmitExternalIP               bool
	OnHostMaintenance            string
	Preemptible                  bool
	Region                       string
	ServiceAccountEmail          string
	Scopes                       []string
	Subnetwork                   string
	Tags                         []string
	Zone                         string
}

type OauthTokenSource added in v1.4.4

type OauthTokenSource struct {
	Path string
}

Define a TokenSource that gets tokens from Vault

func (OauthTokenSource) Token added in v1.4.4

func (ots OauthTokenSource) Token() (*oauth2.Token, error)

type StepCheckExistingImage added in v0.7.5

type StepCheckExistingImage int

StepCheckExistingImage represents a Packer build step that checks if the target image already exists, and aborts immediately if so.

func (*StepCheckExistingImage) Cleanup added in v0.7.5

func (s *StepCheckExistingImage) Cleanup(state multistep.StateBag)

Cleanup.

func (*StepCheckExistingImage) Run added in v0.7.5

Run executes the Packer build step that checks if the image already exists.

type StepCreateImage

type StepCreateImage int

StepCreateImage represents a Packer build step that creates GCE machine images.

func (*StepCreateImage) Cleanup

func (s *StepCreateImage) Cleanup(state multistep.StateBag)

Cleanup.

func (*StepCreateImage) Run

Run executes the Packer build step that creates a GCE machine image.

The image is created from the persistent disk used by the instance. The instance must be deleted and the disk retained before doing this step.

type StepCreateInstance

type StepCreateInstance struct {
	Debug bool
}

StepCreateInstance represents a Packer build step that creates GCE instances.

func (*StepCreateInstance) Cleanup

func (s *StepCreateInstance) Cleanup(state multistep.StateBag)

Cleanup destroys the GCE instance created during the image creation process.

func (*StepCreateInstance) Run

Run executes the Packer build step that creates a GCE instance.

type StepCreateSSHKey

type StepCreateSSHKey struct {
	Debug        bool
	DebugKeyPath string
}

StepCreateSSHKey represents a Packer build step that generates SSH key pairs.

func (*StepCreateSSHKey) Cleanup

func (s *StepCreateSSHKey) Cleanup(state multistep.StateBag)

Nothing to clean up. SSH keys are associated with a single GCE instance.

func (*StepCreateSSHKey) Run

Run executes the Packer build step that generates SSH key pairs. The key pairs are added to the ssh config

type StepCreateWindowsPassword added in v0.11.0

type StepCreateWindowsPassword struct {
	Debug        bool
	DebugKeyPath string
}

StepCreateWindowsPassword represents a Packer build step that sets the windows password on a Windows GCE instance.

func (*StepCreateWindowsPassword) Cleanup added in v0.11.0

func (s *StepCreateWindowsPassword) Cleanup(state multistep.StateBag)

Nothing to clean up. The windows password is only created on the single instance.

func (*StepCreateWindowsPassword) Run added in v0.11.0

Run executes the Packer build step that sets the windows password on a Windows GCE instance.

type StepInstanceInfo

type StepInstanceInfo struct {
	Debug bool
}

stepInstanceInfo represents a Packer build step that gathers GCE instance info.

func (*StepInstanceInfo) Cleanup

func (s *StepInstanceInfo) Cleanup(state multistep.StateBag)

Cleanup.

func (*StepInstanceInfo) Run

Run executes the Packer build step that gathers GCE instance info. This adds "instance_ip" to the multistep state.

type StepTeardownInstance added in v0.7.5

type StepTeardownInstance struct {
	Debug bool
}

StepTeardownInstance represents a Packer build step that tears down GCE instances.

func (*StepTeardownInstance) Cleanup added in v0.7.5

func (s *StepTeardownInstance) Cleanup(state multistep.StateBag)

Deleting the instance does not remove the boot disk. This cleanup removes the disk.

func (*StepTeardownInstance) Run added in v0.7.5

Run executes the Packer build step that tears down a GCE instance.

type StepWaitStartupScript added in v0.12.0

type StepWaitStartupScript int

func (*StepWaitStartupScript) Cleanup added in v0.12.0

func (s *StepWaitStartupScript) Cleanup(state multistep.StateBag)

Cleanup.

func (*StepWaitStartupScript) Run added in v0.12.0

Run reads the instance metadata and looks for the log entry indicating the startup script finished.

type WindowsPasswordConfig added in v0.11.0

type WindowsPasswordConfig struct {
	UserName string    `json:"userName"`
	Modulus  string    `json:"modulus"`
	Exponent string    `json:"exponent"`
	Email    string    `json:"email"`
	ExpireOn time.Time `json:"expireOn"`
	// contains filtered or unexported fields
}

WindowsPasswordConfig is the data structure that GCE needs to encrypt the created windows password.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL