googlecompute

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 45 Imported by: 1

Documentation

Overview

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

Index

Constants

View Source
const BuilderId = "packer.googlecompute"

The unique ID for this builder.

View Source
const EnableOSLoginKey string = "enable-oslogin"
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 ErrStartupScriptMetadata = errors.New("Startup script exited with error.")

ErrStartupScriptMetadata means that the user provided startup script resulted in setting the set-startup-script metadata status to error.

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/%[1]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

if [ $RETVAL -ne 0  ]; then
  echo "Packer startup script exited with exit code: ${RETVAL}"
  SetMetadata %[2]s %[4]s
else
  echo "Packer startup script done."
  SetMetadata %[2]s %[3]s
fi

exit $RETVAL
`, StartupWrappedScriptKey, StartupScriptStatusKey, StartupScriptStatusDone, StartupScriptStatusError)
View Source
var StartupScriptWindows string = ""
View Source
var TemplateFuncs = template.FuncMap{
	"clean_resource_name": templateCleanImageName,
}

Functions

func ApplyIAPTunnel

func ApplyIAPTunnel(c *communicator.Config, port int) error

func RunTunnelCommand

func RunTunnelCommand(cmd *exec.Cmd, timeout int) error

func SupportsIAPTunnel

func SupportsIAPTunnel(c *communicator.Config) bool

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

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

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

func (*Builder) Prepare

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

func (*Builder) Run

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

type Config

type Config struct {
	sdk_common.PackerConfig `mapstructure:",squash"`
	common.Authentication   `mapstructure:",squash"`

	Comm communicator.Config `mapstructure:",squash"`

	// 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 20, which is 20GB.
	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"`
	// Disk encryption key to apply to the created boot disk. 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.
	//
	// examples:
	//
	//  “`json
	//  {
	//     "kmsKeyName": "projects/${project}/locations/${region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
	//  }
	//  “`
	//
	//  “`hcl
	//   disk_encryption_key {
	//     kmsKeyName = "projects/${var.project}/locations/${var.region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
	//   }
	//  “`
	DiskEncryptionKey *common.CustomerEncryptionKey `mapstructure:"disk_encryption_key" required:"false"`
	// Create a instance with enabling nested virtualization.
	EnableNestedVirtualization bool `mapstructure:"enable_nested_virtualization" required:"false"`
	// Create a Shielded VM image with Secure Boot enabled. It helps ensure that
	// the system only runs authentic software by verifying the digital signature
	// of all boot components, and halting the boot process if signature verification
	// fails. [Details](https://cloud.google.com/security/shielded-cloud/shielded-vm)
	EnableSecureBoot bool `mapstructure:"enable_secure_boot" required:"false"`
	// Create a Shielded VM image with virtual trusted platform module
	// Measured Boot enabled. A vTPM is a virtualized trusted platform module,
	// which is a specialized computer chip you can use to protect objects,
	// like keys and certificates, that you use to authenticate access to your
	// system. [Details](https://cloud.google.com/security/shielded-cloud/shielded-vm)
	EnableVtpm bool `mapstructure:"enable_vtpm" required:"false"`
	// Integrity monitoring helps you understand and make decisions about the
	// state of your VM instances. Note: integrity monitoring relies on having
	// vTPM enabled. [Details](https://cloud.google.com/security/shielded-cloud/shielded-vm)
	EnableIntegrityMonitoring bool `mapstructure:"enable_integrity_monitoring" required:"false"`
	// Extra disks to attach to the instance that will build the final image.
	//
	// You may reference an existing external persistent disk, or you can configure
	// a set of disks to be created before the instance is created, and will
	// be deleted upon build completion.
	//
	// Scratch (ephemeral) SSDs are always created at launch, and deleted when the
	// instance is torn-down.
	//
	// Note: local SSDs are not supported on all machine types, refer to the
	// [docs](https://cloud.google.com/compute/docs/disks/local-ssd#choose_number_local_ssds)
	// for more information on that.
	//
	// Refer to the [Extra Disk Attachments](#extra-disk-attachments) section for
	// more information on this configuration type.
	ExtraBlockDevices []common.BlockDevice `mapstructure:"disk_attachment" required:"false"`
	// Whether to use an IAP proxy.
	IAPConfig `mapstructure:",squash"`
	// Skip creating the image. Useful for setting to `true` during a build test stage. Defaults to `false`.
	SkipCreateImage bool `mapstructure:"skip_create_image" 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.
	//
	// examples:
	//
	//  “`json
	//  {
	//     "kmsKeyName": "projects/${project}/locations/${region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
	//  }
	//  “`
	//
	//  “`hcl
	//   image_encryption_key {
	//     kmsKeyName = "projects/${var.project}/locations/${var.region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
	//   }
	//  “`
	ImageEncryptionKey *common.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"`
	// Guest OS features to apply to the created image.
	ImageGuestOsFeatures []string `mapstructure:"image_guest_os_features" required:"false"`
	// The project ID to push the build image into. Defaults to project_id.
	ImageProjectId string `mapstructure:"image_project_id" required:"false"`
	// Storage location, either regional or multi-regional, where snapshot
	// content is to be stored and only accepts 1 value. Always defaults to a nearby regional or multi-regional
	// location.
	//
	// multi-regional example:
	//
	//  “`json
	//  {
	//     "image_storage_locations": ["us"]
	//  }
	//  “`
	// regional example:
	//
	//  “`json
	//  {
	//     "image_storage_locations": ["us-east1"]
	//  }
	//  “`
	ImageStorageLocations []string `mapstructure:"image_storage_locations" 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 "e2-standard-2".
	MachineType string `mapstructure:"machine_type" required:"false"`
	// Metadata applied to the launched instance.
	// All metadata configuration values are expected to be of type string.
	// Google metadata options that take a value of `TRUE` or `FALSE` should be
	// set as a string (i.e  `"TRUE"` `"FALSE"` or `"true"` `"false"`).
	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"`
	// Sets a node affinity label for the launched instance (eg. for sole tenancy).
	// Please see [Provisioning VMs on
	// sole-tenant nodes](https://cloud.google.com/compute/docs/nodes/provisioning-sole-tenant-vms)
	// for more information.
	//
	// “`hcl
	//   key = "workload"
	//   operator = "IN"
	//   values = ["packer"]
	// “`
	NodeAffinities []common.NodeAffinity `mapstructure:"node_affinity" 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"`
	// A list of project IDs to search for the source image. Packer will search the first
	// project ID in the list first, and fall back to the next in the list, until it finds the source image.
	SourceImageProjectId []string `mapstructure:"source_image_project_id" required:"false"`
	// The path to a startup script to run on the launched instance from which the image will
	// be made. When set, the contents of the startup script file will be added to the instance metadata
	// under the `"startup_script"` metadata property. See [Providing startup script contents directly](https://cloud.google.com/compute/docs/startupscript#providing_startup_script_contents_directly) for more details.
	//
	// When using `startup_script_file` the following rules apply:
	// - The contents of the script file will overwrite the value of the `"startup_script"` metadata property at runtime.
	// - The contents of the script file will be wrapped in Packer's startup script wrapper, unless `wrap_startup_script` is disabled. See `wrap_startup_script` for more details.
	// - Not supported by Windows instances. See [Startup Scripts for Windows](https://cloud.google.com/compute/docs/startupscript#providing_a_startup_script_for_windows_instances) for more details.
	StartupScriptFile string `mapstructure:"startup_script_file" required:"false"`
	// The time to wait for windows password to be retrieved. Defaults to "3m".
	WindowsPasswordTimeout time.Duration `mapstructure:"windows_password_timeout" required:"false"`
	// For backwards compatibility this option defaults to `"true"` in the future it will default to `"false"`.
	// If "true", the contents of `startup_script_file` or `"startup_script"` in the instance metadata
	// is wrapped in a Packer specific script that tracks the execution and completion of the provided
	// startup script. The wrapper ensures that the builder will not continue until the startup script has been executed.
	// - The use of the wrapped script file requires that the user or service account
	// running the build has the compute.instance.Metadata role.
	WrapStartupScriptFile config.Trilean `mapstructure:"wrap_startup_script" 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"`
	// If true, OSLogin will be used to manage SSH access to the compute instance by
	// dynamically importing a temporary SSH key to the Google account's login profile,
	// and setting the `enable-oslogin` to `TRUE` in the instance metadata.
	// Optionally, `use_os_login` can be used with an existing `ssh_username` and `ssh_private_key_file`
	// if a SSH key has already been added to the Google account's login profile - See [Adding SSH Keys](https://cloud.google.com/compute/docs/instances/managing-instance-access#add_oslogin_keys).
	//
	// SSH keys can be added to an individual user account
	//
	//“`shell-session
	// $ gcloud compute os-login ssh-keys add --key-file=/home/user/.ssh/my-key.pub
	//
	// $ gcloud compute os-login describe-profile
	//PosixAccounts:
	//- accountId: <project-id>
	//  gid: '34567890754'
	//  homeDirectory: /home/user_example_com
	//  ...
	//  primary: true
	//  uid: '2504818925'
	//  username: /home/user_example_com
	//sshPublicKeys:
	//  000000000000000000000000000000000000000000000000000000000000000a:
	//    fingerprint: 000000000000000000000000000000000000000000000000000000000000000a
	//“`
	//
	// Or SSH keys can be added to an associated service account
	//“`shell-session
	// $ gcloud auth activate-service-account --key-file=<path to service account credentials file (e.g account.json)>
	// $ gcloud compute os-login ssh-keys add --key-file=/home/user/.ssh/my-key.pub
	//
	// $ gcloud compute os-login describe-profile
	//PosixAccounts:
	//- accountId: <project-id>
	//  gid: '34567890754'
	//  homeDirectory: /home/sa_000000000000000000000
	//  ...
	//  primary: true
	//  uid: '2504818925'
	//  username: sa_000000000000000000000
	//sshPublicKeys:
	//  000000000000000000000000000000000000000000000000000000000000000a:
	//    fingerprint: 000000000000000000000000000000000000000000000000000000000000000a
	//“`
	UseOSLogin bool `mapstructure:"use_os_login" required:"false"`
	// The time to wait between the creation of the instance used to create the image,
	// and the addition of SSH configuration, including SSH keys, to that instance.
	// The delay is intended to protect packer from anything in the instance boot
	// sequence that has potential to disrupt the creation of SSH configuration
	// (e.g. SSH user creation, SSH key creation) on the instance.
	// Note: All other instance metadata, including startup scripts, are still added to the instance
	// during it's creation.
	// Example value: `5m`.
	WaitToAddSSHKeys time.Duration `mapstructure:"wait_to_add_ssh_keys"`
	// 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

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

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

type FlatConfig

type FlatConfig struct {
	PackerBuildName              *string                           `mapstructure:"packer_build_name" cty:"packer_build_name" hcl:"packer_build_name"`
	PackerBuilderType            *string                           `mapstructure:"packer_builder_type" cty:"packer_builder_type" hcl:"packer_builder_type"`
	PackerCoreVersion            *string                           `mapstructure:"packer_core_version" cty:"packer_core_version" hcl:"packer_core_version"`
	PackerDebug                  *bool                             `mapstructure:"packer_debug" cty:"packer_debug" hcl:"packer_debug"`
	PackerForce                  *bool                             `mapstructure:"packer_force" cty:"packer_force" hcl:"packer_force"`
	PackerOnError                *string                           `mapstructure:"packer_on_error" cty:"packer_on_error" hcl:"packer_on_error"`
	PackerUserVars               map[string]string                 `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"`
	PackerSensitiveVars          []string                          `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"`
	AccessToken                  *string                           `mapstructure:"access_token" required:"false" cty:"access_token" hcl:"access_token"`
	AccountFile                  *string                           `mapstructure:"account_file" required:"false" cty:"account_file" hcl:"account_file"`
	CredentialsFile              *string                           `mapstructure:"credentials_file" required:"false" cty:"credentials_file" hcl:"credentials_file"`
	CredentialsJSON              *string                           `mapstructure:"credentials_json" required:"false" cty:"credentials_json" hcl:"credentials_json"`
	ImpersonateServiceAccount    *string                           `` /* 127-byte string literal not displayed */
	VaultGCPOauthEngine          *string                           `mapstructure:"vault_gcp_oauth_engine" cty:"vault_gcp_oauth_engine" hcl:"vault_gcp_oauth_engine"`
	Type                         *string                           `mapstructure:"communicator" cty:"communicator" hcl:"communicator"`
	PauseBeforeConnect           *string                           `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"`
	SSHHost                      *string                           `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"`
	SSHPort                      *int                              `mapstructure:"ssh_port" cty:"ssh_port" hcl:"ssh_port"`
	SSHUsername                  *string                           `mapstructure:"ssh_username" cty:"ssh_username" hcl:"ssh_username"`
	SSHPassword                  *string                           `mapstructure:"ssh_password" cty:"ssh_password" hcl:"ssh_password"`
	SSHKeyPairName               *string                           `mapstructure:"ssh_keypair_name" undocumented:"true" cty:"ssh_keypair_name" hcl:"ssh_keypair_name"`
	SSHTemporaryKeyPairName      *string                           `mapstructure:"temporary_key_pair_name" undocumented:"true" cty:"temporary_key_pair_name" hcl:"temporary_key_pair_name"`
	SSHTemporaryKeyPairType      *string                           `mapstructure:"temporary_key_pair_type" cty:"temporary_key_pair_type" hcl:"temporary_key_pair_type"`
	SSHTemporaryKeyPairBits      *int                              `mapstructure:"temporary_key_pair_bits" cty:"temporary_key_pair_bits" hcl:"temporary_key_pair_bits"`
	SSHCiphers                   []string                          `mapstructure:"ssh_ciphers" cty:"ssh_ciphers" hcl:"ssh_ciphers"`
	SSHClearAuthorizedKeys       *bool                             `mapstructure:"ssh_clear_authorized_keys" cty:"ssh_clear_authorized_keys" hcl:"ssh_clear_authorized_keys"`
	SSHKEXAlgos                  []string                          `mapstructure:"ssh_key_exchange_algorithms" cty:"ssh_key_exchange_algorithms" hcl:"ssh_key_exchange_algorithms"`
	SSHPrivateKeyFile            *string                           `mapstructure:"ssh_private_key_file" undocumented:"true" cty:"ssh_private_key_file" hcl:"ssh_private_key_file"`
	SSHCertificateFile           *string                           `mapstructure:"ssh_certificate_file" cty:"ssh_certificate_file" hcl:"ssh_certificate_file"`
	SSHPty                       *bool                             `mapstructure:"ssh_pty" cty:"ssh_pty" hcl:"ssh_pty"`
	SSHTimeout                   *string                           `mapstructure:"ssh_timeout" cty:"ssh_timeout" hcl:"ssh_timeout"`
	SSHWaitTimeout               *string                           `mapstructure:"ssh_wait_timeout" undocumented:"true" cty:"ssh_wait_timeout" hcl:"ssh_wait_timeout"`
	SSHAgentAuth                 *bool                             `mapstructure:"ssh_agent_auth" undocumented:"true" cty:"ssh_agent_auth" hcl:"ssh_agent_auth"`
	SSHDisableAgentForwarding    *bool                             `mapstructure:"ssh_disable_agent_forwarding" cty:"ssh_disable_agent_forwarding" hcl:"ssh_disable_agent_forwarding"`
	SSHHandshakeAttempts         *int                              `mapstructure:"ssh_handshake_attempts" cty:"ssh_handshake_attempts" hcl:"ssh_handshake_attempts"`
	SSHBastionHost               *string                           `mapstructure:"ssh_bastion_host" cty:"ssh_bastion_host" hcl:"ssh_bastion_host"`
	SSHBastionPort               *int                              `mapstructure:"ssh_bastion_port" cty:"ssh_bastion_port" hcl:"ssh_bastion_port"`
	SSHBastionAgentAuth          *bool                             `mapstructure:"ssh_bastion_agent_auth" cty:"ssh_bastion_agent_auth" hcl:"ssh_bastion_agent_auth"`
	SSHBastionUsername           *string                           `mapstructure:"ssh_bastion_username" cty:"ssh_bastion_username" hcl:"ssh_bastion_username"`
	SSHBastionPassword           *string                           `mapstructure:"ssh_bastion_password" cty:"ssh_bastion_password" hcl:"ssh_bastion_password"`
	SSHBastionInteractive        *bool                             `mapstructure:"ssh_bastion_interactive" cty:"ssh_bastion_interactive" hcl:"ssh_bastion_interactive"`
	SSHBastionPrivateKeyFile     *string                           `mapstructure:"ssh_bastion_private_key_file" cty:"ssh_bastion_private_key_file" hcl:"ssh_bastion_private_key_file"`
	SSHBastionCertificateFile    *string                           `mapstructure:"ssh_bastion_certificate_file" cty:"ssh_bastion_certificate_file" hcl:"ssh_bastion_certificate_file"`
	SSHFileTransferMethod        *string                           `mapstructure:"ssh_file_transfer_method" cty:"ssh_file_transfer_method" hcl:"ssh_file_transfer_method"`
	SSHProxyHost                 *string                           `mapstructure:"ssh_proxy_host" cty:"ssh_proxy_host" hcl:"ssh_proxy_host"`
	SSHProxyPort                 *int                              `mapstructure:"ssh_proxy_port" cty:"ssh_proxy_port" hcl:"ssh_proxy_port"`
	SSHProxyUsername             *string                           `mapstructure:"ssh_proxy_username" cty:"ssh_proxy_username" hcl:"ssh_proxy_username"`
	SSHProxyPassword             *string                           `mapstructure:"ssh_proxy_password" cty:"ssh_proxy_password" hcl:"ssh_proxy_password"`
	SSHKeepAliveInterval         *string                           `mapstructure:"ssh_keep_alive_interval" cty:"ssh_keep_alive_interval" hcl:"ssh_keep_alive_interval"`
	SSHReadWriteTimeout          *string                           `mapstructure:"ssh_read_write_timeout" cty:"ssh_read_write_timeout" hcl:"ssh_read_write_timeout"`
	SSHRemoteTunnels             []string                          `mapstructure:"ssh_remote_tunnels" cty:"ssh_remote_tunnels" hcl:"ssh_remote_tunnels"`
	SSHLocalTunnels              []string                          `mapstructure:"ssh_local_tunnels" cty:"ssh_local_tunnels" hcl:"ssh_local_tunnels"`
	SSHPublicKey                 []byte                            `mapstructure:"ssh_public_key" undocumented:"true" cty:"ssh_public_key" hcl:"ssh_public_key"`
	SSHPrivateKey                []byte                            `mapstructure:"ssh_private_key" undocumented:"true" cty:"ssh_private_key" hcl:"ssh_private_key"`
	WinRMUser                    *string                           `mapstructure:"winrm_username" cty:"winrm_username" hcl:"winrm_username"`
	WinRMPassword                *string                           `mapstructure:"winrm_password" cty:"winrm_password" hcl:"winrm_password"`
	WinRMHost                    *string                           `mapstructure:"winrm_host" cty:"winrm_host" hcl:"winrm_host"`
	WinRMNoProxy                 *bool                             `mapstructure:"winrm_no_proxy" cty:"winrm_no_proxy" hcl:"winrm_no_proxy"`
	WinRMPort                    *int                              `mapstructure:"winrm_port" cty:"winrm_port" hcl:"winrm_port"`
	WinRMTimeout                 *string                           `mapstructure:"winrm_timeout" cty:"winrm_timeout" hcl:"winrm_timeout"`
	WinRMUseSSL                  *bool                             `mapstructure:"winrm_use_ssl" cty:"winrm_use_ssl" hcl:"winrm_use_ssl"`
	WinRMInsecure                *bool                             `mapstructure:"winrm_insecure" cty:"winrm_insecure" hcl:"winrm_insecure"`
	WinRMUseNTLM                 *bool                             `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm" hcl:"winrm_use_ntlm"`
	ProjectId                    *string                           `mapstructure:"project_id" required:"true" cty:"project_id" hcl:"project_id"`
	AcceleratorType              *string                           `mapstructure:"accelerator_type" required:"false" cty:"accelerator_type" hcl:"accelerator_type"`
	AcceleratorCount             *int64                            `mapstructure:"accelerator_count" required:"false" cty:"accelerator_count" hcl:"accelerator_count"`
	Address                      *string                           `mapstructure:"address" required:"false" cty:"address" hcl:"address"`
	DisableDefaultServiceAccount *bool                             `` /* 139-byte string literal not displayed */
	DiskName                     *string                           `mapstructure:"disk_name" required:"false" cty:"disk_name" hcl:"disk_name"`
	DiskSizeGb                   *int64                            `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"`
	DiskType                     *string                           `mapstructure:"disk_type" required:"false" cty:"disk_type" hcl:"disk_type"`
	DiskEncryptionKey            *common.FlatCustomerEncryptionKey `mapstructure:"disk_encryption_key" required:"false" cty:"disk_encryption_key" hcl:"disk_encryption_key"`
	EnableNestedVirtualization   *bool                             `` /* 130-byte string literal not displayed */
	EnableSecureBoot             *bool                             `mapstructure:"enable_secure_boot" required:"false" cty:"enable_secure_boot" hcl:"enable_secure_boot"`
	EnableVtpm                   *bool                             `mapstructure:"enable_vtpm" required:"false" cty:"enable_vtpm" hcl:"enable_vtpm"`
	EnableIntegrityMonitoring    *bool                             `` /* 127-byte string literal not displayed */
	ExtraBlockDevices            []common.FlatBlockDevice          `mapstructure:"disk_attachment" required:"false" cty:"disk_attachment" hcl:"disk_attachment"`
	IAP                          *bool                             `mapstructure:"use_iap" required:"false" cty:"use_iap" hcl:"use_iap"`
	IAPLocalhostPort             *int                              `mapstructure:"iap_localhost_port" cty:"iap_localhost_port" hcl:"iap_localhost_port"`
	IAPHashBang                  *string                           `mapstructure:"iap_hashbang" required:"false" cty:"iap_hashbang" hcl:"iap_hashbang"`
	IAPExt                       *string                           `mapstructure:"iap_ext" required:"false" cty:"iap_ext" hcl:"iap_ext"`
	IAPTunnelLaunchWait          *int                              `mapstructure:"iap_tunnel_launch_wait" required:"false" cty:"iap_tunnel_launch_wait" hcl:"iap_tunnel_launch_wait"`
	SkipCreateImage              *bool                             `mapstructure:"skip_create_image" required:"false" cty:"skip_create_image" hcl:"skip_create_image"`
	ImageName                    *string                           `mapstructure:"image_name" required:"false" cty:"image_name" hcl:"image_name"`
	ImageDescription             *string                           `mapstructure:"image_description" required:"false" cty:"image_description" hcl:"image_description"`
	ImageEncryptionKey           *common.FlatCustomerEncryptionKey `mapstructure:"image_encryption_key" required:"false" cty:"image_encryption_key" hcl:"image_encryption_key"`
	ImageFamily                  *string                           `mapstructure:"image_family" required:"false" cty:"image_family" hcl:"image_family"`
	ImageLabels                  map[string]string                 `mapstructure:"image_labels" required:"false" cty:"image_labels" hcl:"image_labels"`
	ImageLicenses                []string                          `mapstructure:"image_licenses" required:"false" cty:"image_licenses" hcl:"image_licenses"`
	ImageGuestOsFeatures         []string                          `mapstructure:"image_guest_os_features" required:"false" cty:"image_guest_os_features" hcl:"image_guest_os_features"`
	ImageProjectId               *string                           `mapstructure:"image_project_id" required:"false" cty:"image_project_id" hcl:"image_project_id"`
	ImageStorageLocations        []string                          `mapstructure:"image_storage_locations" required:"false" cty:"image_storage_locations" hcl:"image_storage_locations"`
	InstanceName                 *string                           `mapstructure:"instance_name" required:"false" cty:"instance_name" hcl:"instance_name"`
	Labels                       map[string]string                 `mapstructure:"labels" required:"false" cty:"labels" hcl:"labels"`
	MachineType                  *string                           `mapstructure:"machine_type" required:"false" cty:"machine_type" hcl:"machine_type"`
	Metadata                     map[string]string                 `mapstructure:"metadata" required:"false" cty:"metadata" hcl:"metadata"`
	MetadataFiles                map[string]string                 `mapstructure:"metadata_files" cty:"metadata_files" hcl:"metadata_files"`
	MinCpuPlatform               *string                           `mapstructure:"min_cpu_platform" required:"false" cty:"min_cpu_platform" hcl:"min_cpu_platform"`
	Network                      *string                           `mapstructure:"network" required:"false" cty:"network" hcl:"network"`
	NetworkProjectId             *string                           `mapstructure:"network_project_id" required:"false" cty:"network_project_id" hcl:"network_project_id"`
	OmitExternalIP               *bool                             `mapstructure:"omit_external_ip" required:"false" cty:"omit_external_ip" hcl:"omit_external_ip"`
	OnHostMaintenance            *string                           `mapstructure:"on_host_maintenance" required:"false" cty:"on_host_maintenance" hcl:"on_host_maintenance"`
	Preemptible                  *bool                             `mapstructure:"preemptible" required:"false" cty:"preemptible" hcl:"preemptible"`
	NodeAffinities               []common.FlatNodeAffinity         `mapstructure:"node_affinity" required:"false" cty:"node_affinity" hcl:"node_affinity"`
	StateTimeout                 *string                           `mapstructure:"state_timeout" required:"false" cty:"state_timeout" hcl:"state_timeout"`
	Region                       *string                           `mapstructure:"region" required:"false" cty:"region" hcl:"region"`
	Scopes                       []string                          `mapstructure:"scopes" required:"false" cty:"scopes" hcl:"scopes"`
	ServiceAccountEmail          *string                           `mapstructure:"service_account_email" required:"false" cty:"service_account_email" hcl:"service_account_email"`
	SourceImage                  *string                           `mapstructure:"source_image" required:"true" cty:"source_image" hcl:"source_image"`
	SourceImageFamily            *string                           `mapstructure:"source_image_family" required:"true" cty:"source_image_family" hcl:"source_image_family"`
	SourceImageProjectId         []string                          `mapstructure:"source_image_project_id" required:"false" cty:"source_image_project_id" hcl:"source_image_project_id"`
	StartupScriptFile            *string                           `mapstructure:"startup_script_file" required:"false" cty:"startup_script_file" hcl:"startup_script_file"`
	WindowsPasswordTimeout       *string                           `mapstructure:"windows_password_timeout" required:"false" cty:"windows_password_timeout" hcl:"windows_password_timeout"`
	WrapStartupScriptFile        *bool                             `mapstructure:"wrap_startup_script" required:"false" cty:"wrap_startup_script" hcl:"wrap_startup_script"`
	Subnetwork                   *string                           `mapstructure:"subnetwork" required:"false" cty:"subnetwork" hcl:"subnetwork"`
	Tags                         []string                          `mapstructure:"tags" required:"false" cty:"tags" hcl:"tags"`
	UseInternalIP                *bool                             `mapstructure:"use_internal_ip" required:"false" cty:"use_internal_ip" hcl:"use_internal_ip"`
	UseOSLogin                   *bool                             `mapstructure:"use_os_login" required:"false" cty:"use_os_login" hcl:"use_os_login"`
	WaitToAddSSHKeys             *string                           `mapstructure:"wait_to_add_ssh_keys" cty:"wait_to_add_ssh_keys" hcl:"wait_to_add_ssh_keys"`
	Zone                         *string                           `mapstructure:"zone" required:"true" cty:"zone" hcl:"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

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 FlatIAPConfig

type FlatIAPConfig struct {
	IAP                 *bool   `mapstructure:"use_iap" required:"false" cty:"use_iap" hcl:"use_iap"`
	IAPLocalhostPort    *int    `mapstructure:"iap_localhost_port" cty:"iap_localhost_port" hcl:"iap_localhost_port"`
	IAPHashBang         *string `mapstructure:"iap_hashbang" required:"false" cty:"iap_hashbang" hcl:"iap_hashbang"`
	IAPExt              *string `mapstructure:"iap_ext" required:"false" cty:"iap_ext" hcl:"iap_ext"`
	IAPTunnelLaunchWait *int    `mapstructure:"iap_tunnel_launch_wait" required:"false" cty:"iap_tunnel_launch_wait" hcl:"iap_tunnel_launch_wait"`
}

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

func (*FlatIAPConfig) HCL2Spec

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

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

type IAPConfig

type IAPConfig struct {
	// Whether to use an IAP proxy.
	// Prerequisites and limitations for using IAP:
	// - You must manually enable the IAP API in the Google Cloud console.
	// - You must have the gcloud sdk installed on the computer running Packer.
	// - If you use a service account, you must add it to project level IAP permissions
	//   in https://console.cloud.google.com/security/iap. To do so, click
	//   "project" > "SSH and TCP resources" > "All Tunnel Resources" >
	//   "Add Member". Then add your service account and choose the role
	//   "IAP-secured Tunnel User" and add any conditions you may care about.
	IAP bool `mapstructure:"use_iap" required:"false"`
	// Which port to connect the local end of the IAM localhost proxy to. If
	// left blank, Packer will choose a port for you from available ports.
	IAPLocalhostPort int `mapstructure:"iap_localhost_port"`
	// What "hashbang" to use to invoke script that sets up gcloud.
	// Default: "/bin/sh"
	IAPHashBang string `mapstructure:"iap_hashbang" required:"false"`
	// What file extension to use for script that sets up gcloud.
	// Default: ".sh"
	IAPExt string `mapstructure:"iap_ext" required:"false"`
	// How long to wait, in seconds, before assuming a tunnel launch was
	// successful. Defaults to 30 seconds for SSH or 40 seconds for WinRM.
	IAPTunnelLaunchWait int `mapstructure:"iap_tunnel_launch_wait" required:"false"`
}

StepStartTunnel represents a Packer build step that launches an IAP tunnel

func (*IAPConfig) FlatMapstructure

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

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

type RetryableTunnelError

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

func (RetryableTunnelError) Error

func (e RetryableTunnelError) Error() string

type StepCheckExistingImage

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

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

Cleanup.

func (*StepCheckExistingImage) Run

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

type StepCreateDisks added in v1.1.1

type StepCreateDisks struct {
	DiskConfiguration []common.BlockDevice
}

func (*StepCreateDisks) Cleanup added in v1.1.1

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

func (*StepCreateDisks) Run added in v1.1.1

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
	GeneratedData *packerbuilderdata.GeneratedData
}

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 StepCreateWindowsPassword

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

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

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

func (*StepCreateWindowsPassword) Run

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

type StepImportOSLoginSSHKey

type StepImportOSLoginSSHKey struct {
	Debug         bool
	TokeninfoFunc func() (*oauth2.Tokeninfo, error)

	GCEUserFunc func() string
	// contains filtered or unexported fields
}

StepImportOSLoginSSHKey imports a temporary SSH key pair into a GCE login profile.

func (*StepImportOSLoginSSHKey) Cleanup

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

Cleanup the SSH Key that we added to the POSIX account

func (*StepImportOSLoginSSHKey) Run

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

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 StepStartTunnel

type StepStartTunnel struct {
	IAPConf            *IAPConfig
	CommConf           *communicator.Config
	AccountFile        string
	ImpersonateAccount string
	ProjectId          string
	// contains filtered or unexported fields
}

func (*StepStartTunnel) Cleanup

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

Cleanup stops the IAP tunnel and cleans up processes.

func (*StepStartTunnel) ConfigureLocalHostPort

func (s *StepStartTunnel) ConfigureLocalHostPort(ctx context.Context) error

func (*StepStartTunnel) Run

Run executes the Packer build step that creates an IAP tunnel.

type StepTeardownInstance

type StepTeardownInstance struct {
	Debug bool
}

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

func (*StepTeardownInstance) Cleanup

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

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

func (*StepTeardownInstance) Run

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

type StepWaitStartupScript

type StepWaitStartupScript int

StepWaitStartupScript is a trivial implementation of a Packer multistep It can be used for tracking the set-startup-script metadata status.

func (*StepWaitStartupScript) Cleanup

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

Cleanup.

func (*StepWaitStartupScript) Run

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

type TunnelDriver

type TunnelDriver interface {
	StartTunnel(context.Context, string, int) error
	StopTunnel()
}

func NewTunnelDriver

func NewTunnelDriver() TunnelDriver

type TunnelDriverLinux

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

func (*TunnelDriverLinux) StartTunnel

func (t *TunnelDriverLinux) StartTunnel(cancelCtx context.Context, tempScriptFileName string, timeout int) error

func (*TunnelDriverLinux) StopTunnel

func (t *TunnelDriverLinux) StopTunnel()

Jump to

Keyboard shortcuts

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