Commit b78b119a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

amazon/*: fix merge issues with lib switch

parent 44b980e6
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"unicode" "unicode"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/credentials"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
) )
...@@ -22,16 +23,16 @@ type AccessConfig struct { ...@@ -22,16 +23,16 @@ type AccessConfig struct {
// Config returns a valid aws.Config object for access to AWS services, or // Config returns a valid aws.Config object for access to AWS services, or
// an error if the authentication and region couldn't be resolved // an error if the authentication and region couldn't be resolved
func (c *AccessConfig) Config() (*aws.Config, error) { func (c *AccessConfig) Config() (*aws.Config, error) {
credsProvider := aws.DetectCreds(c.AccessKey, c.SecretKey, c.Token) creds := credentials.NewChainCredentials([]credentials.Provider{
&credentials.StaticProvider{Value: credentials.Value{
creds, err := credsProvider.Credentials() AccessKeyID: c.AccessKey,
if err != nil { SecretAccessKey: c.SecretKey,
return nil, err SessionToken: c.Token,
} }},
&credentials.EnvProvider{},
c.AccessKey = creds.AccessKeyID &credentials.SharedCredentialsProvider{Filename: "", Profile: ""},
c.SecretKey = creds.SecretAccessKey &credentials.EC2RoleProvider{},
c.Token = creds.SessionToken })
region, err := c.Region() region, err := c.Region()
if err != nil { if err != nil {
...@@ -40,7 +41,8 @@ func (c *AccessConfig) Config() (*aws.Config, error) { ...@@ -40,7 +41,8 @@ func (c *AccessConfig) Config() (*aws.Config, error) {
return &aws.Config{ return &aws.Config{
Region: region, Region: region,
Credentials: credsProvider, Credentials: creds,
MaxRetries: 11,
}, nil }, nil
} }
......
package common package common
import ( import (
"fmt"
"github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"sync" "sync"
"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/service/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
...@@ -13,7 +12,8 @@ import ( ...@@ -13,7 +12,8 @@ import (
) )
type StepAMIRegionCopy struct { type StepAMIRegionCopy struct {
Regions []string AccessConfig *AccessConfig
Regions []string
} }
func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction { func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
...@@ -37,7 +37,7 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction { ...@@ -37,7 +37,7 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
go func(region string) { go func(region string) {
defer wg.Done() defer wg.Done()
id, err := amiRegionCopy(state, ec2conn.Config.Credentials, ami, region, ec2conn.Config.Region) id, err := amiRegionCopy(state, s.AccessConfig, ami, region, ec2conn.Config.Region)
lock.Lock() lock.Lock()
defer lock.Unlock() defer lock.Unlock()
...@@ -69,15 +69,17 @@ func (s *StepAMIRegionCopy) Cleanup(state multistep.StateBag) { ...@@ -69,15 +69,17 @@ func (s *StepAMIRegionCopy) Cleanup(state multistep.StateBag) {
// amiRegionCopy does a copy for the given AMI to the target region and // amiRegionCopy does a copy for the given AMI to the target region and
// returns the resulting ID or error. // returns the resulting ID or error.
func amiRegionCopy(state multistep.StateBag, auth aws.CredentialsProvider, imageId string, func amiRegionCopy(state multistep.StateBag, config *AccessConfig, imageId string,
target string, source string) (string, error) { target string, source string) (string, error) {
// Connect to the region where the AMI will be copied to // Connect to the region where the AMI will be copied to
config := &aws.Config{ awsConfig, err := config.Config()
Credentials: auth, if err != nil {
Region: target, return "", err
} }
regionconn := ec2.New(config) awsConfig.Region = target
regionconn := ec2.New(awsConfig)
resp, err := regionconn.CopyImage(&ec2.CopyImageInput{ resp, err := regionconn.CopyImage(&ec2.CopyImageInput{
SourceRegion: &source, SourceRegion: &source,
SourceImageID: &imageId, SourceImageID: &imageId,
......
...@@ -121,7 +121,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -121,7 +121,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&stepModifyInstance{}, &stepModifyInstance{},
&stepCreateAMI{}, &stepCreateAMI{},
&awscommon.StepAMIRegionCopy{ &awscommon.StepAMIRegionCopy{
Regions: b.config.AMIRegions, AccessConfig: &b.config.AccessConfig,
Regions: b.config.AMIRegions,
}, },
&awscommon.StepModifyAMIAttributes{ &awscommon.StepModifyAMIAttributes{
Description: b.config.AMIDescription, Description: b.config.AMIDescription,
......
...@@ -203,7 +203,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -203,7 +203,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}, },
&StepRegisterAMI{}, &StepRegisterAMI{},
&awscommon.StepAMIRegionCopy{ &awscommon.StepAMIRegionCopy{
Regions: b.config.AMIRegions, AccessConfig: &b.config.AccessConfig,
Regions: b.config.AMIRegions,
}, },
&awscommon.StepModifyAMIAttributes{ &awscommon.StepModifyAMIAttributes{
Description: b.config.AMIDescription, Description: b.config.AMIDescription,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment