Commit 68a6a0df authored by Chris Bednarski's avatar Chris Bednarski

Merge pull request #2523 from mitchellh/b-aws-0.7.0

Updated AWS SDK calls to match the 0.7.0 release of the AWS SDK
parents 8a426bea 28bf1877
......@@ -5,7 +5,6 @@ import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep"
awscommon "github.com/mitchellh/packer/builder/amazon/common"
......@@ -52,12 +51,12 @@ func (s *StepCreateVolume) Run(state multistep.StateBag) multistep.StepAction {
}
createVolume := &ec2.CreateVolumeInput{
AvailabilityZone: instance.Placement.AvailabilityZone,
Size: aws.Long(vs),
Size: aws.Int64(vs),
SnapshotID: rootDevice.EBS.SnapshotID,
VolumeType: rootDevice.EBS.VolumeType,
IOPS: rootDevice.EBS.IOPS,
}
log.Printf("Create args: %s", awsutil.StringValue(createVolume))
log.Printf("Create args: %s", createVolume)
createVolumeResp, err := ec2conn.CreateVolume(createVolume)
if err != nil {
......
......@@ -34,7 +34,7 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
}
if s.RootVolumeSize > *newDevice.EBS.VolumeSize {
newDevice.EBS.VolumeSize = aws.Long(s.RootVolumeSize)
newDevice.EBS.VolumeSize = aws.Int64(s.RootVolumeSize)
}
}
......@@ -64,7 +64,7 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
// Set the AMI ID in the state
ui.Say(fmt.Sprintf("AMI: %s", *registerResp.ImageID))
amis := make(map[string]string)
amis[ec2conn.Config.Region] = *registerResp.ImageID
amis[*ec2conn.Config.Region] = *registerResp.ImageID
state.Put("amis", amis)
// Wait for the image to become ready
......
......@@ -40,9 +40,9 @@ func (c *AccessConfig) Config() (*aws.Config, error) {
}
return &aws.Config{
Region: region,
Region: aws.String(region),
Credentials: creds,
MaxRetries: 11,
MaxRetries: aws.Int(11),
}, nil
}
......
......@@ -70,7 +70,7 @@ func (a *Artifact) Destroy() error {
regionConfig := &aws.Config{
Credentials: a.Conn.Config.Credentials,
Region: region,
Region: aws.String(region),
}
regionConn := ec2.New(regionConfig)
......
......@@ -32,20 +32,20 @@ func buildBlockDevices(b []BlockDevice) []*ec2.BlockDeviceMapping {
for _, blockDevice := range b {
ebsBlockDevice := &ec2.EBSBlockDevice{
VolumeType: aws.String(blockDevice.VolumeType),
VolumeSize: aws.Long(blockDevice.VolumeSize),
DeleteOnTermination: aws.Boolean(blockDevice.DeleteOnTermination),
VolumeSize: aws.Int64(blockDevice.VolumeSize),
DeleteOnTermination: aws.Bool(blockDevice.DeleteOnTermination),
}
// IOPS is only valid for SSD Volumes
if blockDevice.VolumeType != "" && blockDevice.VolumeType != "standard" && blockDevice.VolumeType != "gp2" {
ebsBlockDevice.IOPS = aws.Long(blockDevice.IOPS)
ebsBlockDevice.IOPS = aws.Int64(blockDevice.IOPS)
}
// You cannot specify Encrypted if you specify a Snapshot ID
if blockDevice.SnapshotId != "" {
ebsBlockDevice.SnapshotID = aws.String(blockDevice.SnapshotId)
} else if blockDevice.Encrypted {
ebsBlockDevice.Encrypted = aws.Boolean(blockDevice.Encrypted)
ebsBlockDevice.Encrypted = aws.Bool(blockDevice.Encrypted)
}
mapping := &ec2.BlockDeviceMapping{
......
......@@ -5,7 +5,6 @@ import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/service/ec2"
)
......@@ -29,8 +28,8 @@ func TestBlockDevice(t *testing.T) {
EBS: &ec2.EBSBlockDevice{
SnapshotID: aws.String("snap-1234"),
VolumeType: aws.String("standard"),
VolumeSize: aws.Long(8),
DeleteOnTermination: aws.Boolean(true),
VolumeSize: aws.Int64(8),
DeleteOnTermination: aws.Bool(true),
},
},
},
......@@ -45,8 +44,8 @@ func TestBlockDevice(t *testing.T) {
VirtualName: aws.String(""),
EBS: &ec2.EBSBlockDevice{
VolumeType: aws.String(""),
VolumeSize: aws.Long(8),
DeleteOnTermination: aws.Boolean(false),
VolumeSize: aws.Int64(8),
DeleteOnTermination: aws.Bool(false),
},
},
},
......@@ -64,9 +63,9 @@ func TestBlockDevice(t *testing.T) {
VirtualName: aws.String(""),
EBS: &ec2.EBSBlockDevice{
VolumeType: aws.String("io1"),
VolumeSize: aws.Long(8),
DeleteOnTermination: aws.Boolean(true),
IOPS: aws.Long(1000),
VolumeSize: aws.Int64(8),
DeleteOnTermination: aws.Bool(true),
IOPS: aws.Int64(1000),
},
},
},
......@@ -93,13 +92,13 @@ func TestBlockDevice(t *testing.T) {
got := blockDevices.BuildAMIDevices()
if !reflect.DeepEqual(expected, got) {
t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s",
awsutil.StringValue(expected), awsutil.StringValue(got))
expected, got)
}
if !reflect.DeepEqual(expected, blockDevices.BuildLaunchDevices()) {
t.Fatalf("Bad block device, \nexpected: %s\n\ngot: %s",
awsutil.StringValue(expected),
awsutil.StringValue(blockDevices.BuildLaunchDevices()))
expected,
blockDevices.BuildLaunchDevices())
}
}
}
......@@ -5,6 +5,7 @@ import (
"sync"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep"
......@@ -21,7 +22,7 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
ec2conn := state.Get("ec2").(*ec2.EC2)
ui := state.Get("ui").(packer.Ui)
amis := state.Get("amis").(map[string]string)
ami := amis[ec2conn.Config.Region]
ami := amis[*ec2conn.Config.Region]
if len(s.Regions) == 0 {
return multistep.ActionContinue
......@@ -33,7 +34,7 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
var wg sync.WaitGroup
errs := new(packer.MultiError)
for _, region := range s.Regions {
if region == ec2conn.Config.Region {
if region == *ec2conn.Config.Region {
ui.Message(fmt.Sprintf(
"Avoiding copying AMI to duplicate region %s", region))
continue
......@@ -44,7 +45,7 @@ func (s *StepAMIRegionCopy) Run(state multistep.StateBag) multistep.StepAction {
go func(region string) {
defer wg.Done()
id, err := amiRegionCopy(state, s.AccessConfig, s.Name, ami, region, ec2conn.Config.Region)
id, err := amiRegionCopy(state, s.AccessConfig, s.Name, ami, region, *ec2conn.Config.Region)
lock.Lock()
defer lock.Unlock()
......@@ -84,7 +85,7 @@ func amiRegionCopy(state multistep.StateBag, config *AccessConfig, name string,
if err != nil {
return "", err
}
awsConfig.Region = target
awsConfig.Region = aws.String(target)
regionconn := ec2.New(awsConfig)
resp, err := regionconn.CopyImage(&ec2.CopyImageInput{
......
......@@ -36,7 +36,7 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
regionconn := ec2.New(&aws.Config{
Credentials: ec2conn.Config.Credentials,
Region: region,
Region: aws.String(region),
})
// Retrieve image list for given AMI
......
......@@ -90,7 +90,7 @@ func (s *StepModifyAMIAttributes) Run(state multistep.StateBag) multistep.StepAc
ui.Say(fmt.Sprintf("Modifying attributes on AMI (%s)...", ami))
regionconn := ec2.New(&aws.Config{
Credentials: ec2conn.Config.Credentials,
Region: region,
Region: aws.String(region),
})
for name, input := range options {
ui.Message(fmt.Sprintf("Modifying: %s", name))
......
......@@ -141,8 +141,8 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
ImageID: &s.SourceAMI,
InstanceType: &s.InstanceType,
UserData: &userData,
MaxCount: aws.Long(1),
MinCount: aws.Long(1),
MaxCount: aws.Int64(1),
MinCount: aws.Int64(1),
IAMInstanceProfile: &ec2.IAMInstanceProfileSpecification{Name: &s.IamInstanceProfile},
BlockDeviceMappings: s.BlockDevices.BuildLaunchDevices(),
Placement: &ec2.Placement{AvailabilityZone: &s.AvailabilityZone},
......@@ -151,11 +151,11 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
if s.SubnetId != "" && s.AssociatePublicIpAddress {
runOpts.NetworkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{
&ec2.InstanceNetworkInterfaceSpecification{
DeviceIndex: aws.Long(0),
DeviceIndex: aws.Int64(0),
AssociatePublicIPAddress: &s.AssociatePublicIpAddress,
SubnetID: &s.SubnetId,
Groups: securityGroupIds,
DeleteOnTermination: aws.Boolean(true),
DeleteOnTermination: aws.Bool(true),
},
}
} else {
......@@ -185,11 +185,11 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
IAMInstanceProfile: &ec2.IAMInstanceProfileSpecification{Name: &s.IamInstanceProfile},
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
&ec2.InstanceNetworkInterfaceSpecification{
DeviceIndex: aws.Long(0),
DeviceIndex: aws.Int64(0),
AssociatePublicIPAddress: &s.AssociatePublicIpAddress,
SubnetID: &s.SubnetId,
Groups: securityGroupIds,
DeleteOnTermination: aws.Boolean(true),
DeleteOnTermination: aws.Bool(true),
},
},
Placement: &ec2.SpotPlacement{
......
......@@ -59,8 +59,8 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
req := &ec2.AuthorizeSecurityGroupIngressInput{
GroupID: groupResp.GroupID,
IPProtocol: aws.String("tcp"),
FromPort: aws.Long(int64(port)),
ToPort: aws.Long(int64(port)),
FromPort: aws.Int64(int64(port)),
ToPort: aws.Int64(int64(port)),
CIDRIP: aws.String("0.0.0.0/0"),
}
......
......@@ -38,7 +38,7 @@ func (s *stepCreateAMI) Run(state multistep.StateBag) multistep.StepAction {
// Set the AMI ID in the state
ui.Message(fmt.Sprintf("AMI: %s", *createResp.ImageID))
amis := make(map[string]string)
amis[ec2conn.Config.Region] = *createResp.ImageID
amis[*ec2conn.Config.Region] = *createResp.ImageID
state.Put("amis", amis)
// Wait for the image to become ready
......
......@@ -44,7 +44,7 @@ func (s *StepRegisterAMI) Run(state multistep.StateBag) multistep.StepAction {
// Set the AMI ID in the state
ui.Say(fmt.Sprintf("AMI: %s", *registerResp.ImageID))
amis := make(map[string]string)
amis[ec2conn.Config.Region] = *registerResp.ImageID
amis[*ec2conn.Config.Region] = *registerResp.ImageID
state.Put("amis", amis)
// Wait for the image to become ready
......
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