From 9fb778c012edb280219744787a9caaad211bf0dc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Jul 2013 13:28:49 +0900 Subject: [PATCH] builder/common: common config struct for Packer configs --- builder/amazon/ebs/builder.go | 3 +-- builder/common/packer_config.go | 10 ++++++++++ builder/digitalocean/builder.go | 4 ++-- builder/virtualbox/builder.go | 6 ++---- builder/vmware/builder.go | 6 ++---- 5 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 builder/common/packer_config.go diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 61df25b15..ab241e145 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -22,6 +22,7 @@ import ( const BuilderId = "mitchellh.amazonebs" type config struct { + common.PackerConfig `mapstructure:",squash"` awscommon.AccessConfig `mapstructure:",squash"` VpcId string `mapstructure:"vpc_id"` SubnetId string `mapstructure:"subnet_id"` @@ -29,8 +30,6 @@ type config struct { // Configuration of the resulting AMI AMIName string `mapstructure:"ami_name"` - - PackerDebug bool `mapstructure:"packer_debug"` } type Builder struct { diff --git a/builder/common/packer_config.go b/builder/common/packer_config.go new file mode 100644 index 000000000..f51b92e0b --- /dev/null +++ b/builder/common/packer_config.go @@ -0,0 +1,10 @@ +package common + +// PackerConfig is a struct that contains the configuration keys that +// are sent by packer, properly tagged already so mapstructure can load +// them. Embed this structure into your configuration class to get it. +type PackerConfig struct { + PackerBuildName string `mapstructure:"packer_build_name"` + PackerDebug bool `mapstructure:"packer_debug"` + PackerForce bool `mapstructure:"packer_force"` +} diff --git a/builder/digitalocean/builder.go b/builder/digitalocean/builder.go index ae79f7c24..c4ab8c5bc 100644 --- a/builder/digitalocean/builder.go +++ b/builder/digitalocean/builder.go @@ -28,6 +28,8 @@ type snapshotNameData struct { // to use while communicating with DO and describes the image // you are creating type config struct { + common.PackerConfig `mapstructure:",squash"` + ClientID string `mapstructure:"client_id"` APIKey string `mapstructure:"api_key"` RegionID uint `mapstructure:"region_id"` @@ -38,8 +40,6 @@ type config struct { SSHUsername string `mapstructure:"ssh_username"` SSHPort uint `mapstructure:"ssh_port"` - PackerDebug bool `mapstructure:"packer_debug"` - RawSnapshotName string `mapstructure:"snapshot_name"` RawSSHTimeout string `mapstructure:"ssh_timeout"` RawEventDelay string `mapstructure:"event_delay"` diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index af6ffd35a..25a2855f8 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -24,6 +24,8 @@ type Builder struct { } type config struct { + common.PackerConfig `mapstructure:",squash"` + BootCommand []string `mapstructure:"boot_command"` DiskSize uint `mapstructure:"disk_size"` FloppyFiles []string `mapstructure:"floppy_files"` @@ -49,10 +51,6 @@ type config struct { VBoxManage [][]string `mapstructure:"vboxmanage"` VMName string `mapstructure:"vm_name"` - PackerBuildName string `mapstructure:"packer_build_name"` - PackerDebug bool `mapstructure:"packer_debug"` - PackerForce bool `mapstructure:"packer_force"` - RawBootWait string `mapstructure:"boot_wait"` RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index d2e2ba3ed..48d19a3cf 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -25,6 +25,8 @@ type Builder struct { } type config struct { + common.PackerConfig `mapstructure:",squash"` + DiskName string `mapstructure:"vmdk_name"` DiskSize uint `mapstructure:"disk_size"` FloppyFiles []string `mapstructure:"floppy_files"` @@ -50,10 +52,6 @@ type config struct { VNCPortMin uint `mapstructure:"vnc_port_min"` VNCPortMax uint `mapstructure:"vnc_port_max"` - PackerBuildName string `mapstructure:"packer_build_name"` - PackerDebug bool `mapstructure:"packer_debug"` - PackerForce bool `mapstructure:"packer_force"` - RawBootWait string `mapstructure:"boot_wait"` RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`