diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go new file mode 100644 index 000000000..c3819875a --- /dev/null +++ b/builder/amazon/common/access_config.go @@ -0,0 +1,21 @@ +package common + +import ( + "github.com/mitchellh/goamz/aws" +) + +// AccessConfig is for common configuration related to AWS access +type AccessConfig struct { + AccessKey string `mapstructure:"access_key"` + SecretKey string `mapstructure:"secret_key"` +} + +// Auth returns a valid aws.Auth object for access to AWS services, or +// an error if the authentication couldn't be resolved. +func (c *AccessConfig) Auth() (aws.Auth, error) { + return aws.GetAuth(c.AccessKey, c.SecretKey) +} + +func (c *AccessConfig) Validate() []error { + return nil +} diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 6063f995a..6b39a37ca 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -11,6 +11,7 @@ import ( "github.com/mitchellh/goamz/aws" "github.com/mitchellh/goamz/ec2" "github.com/mitchellh/multistep" + awscommon "github.com/mitchellh/packer/builder/amazon/common" "github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/packer" "log" @@ -22,9 +23,7 @@ import ( const BuilderId = "mitchellh.amazonebs" type config struct { - // Access information - AccessKey string `mapstructure:"access_key"` - SecretKey string `mapstructure:"secret_key"` + awscommon.AccessConfig `mapstructure:",squash"` // Information for the source instance Region string @@ -123,7 +122,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe panic("region not found") } - auth, err := aws.GetAuth(b.config.AccessKey, b.config.SecretKey) + auth, err := b.config.AccessConfig.Auth() if err != nil { return nil, err } diff --git a/builder/amazon/instance/builder_test.go b/builder/amazon/instance/builder_test.go index ac214051f..76c72f772 100644 --- a/builder/amazon/instance/builder_test.go +++ b/builder/amazon/instance/builder_test.go @@ -12,4 +12,3 @@ func TestBuilder_ImplementsBuilder(t *testing.T) { t.Fatalf("Builder should be a builder") } } -