From 28bf1877c24a4f62eade44309bb4931066d3bedd Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Tue, 28 Jul 2015 17:10:21 -0700 Subject: [PATCH] Updated AWS SDK calls to match the 0.7.0 release of the AWS SDK --- builder/amazon/chroot/step_create_volume.go | 5 ++--- builder/amazon/chroot/step_register_ami.go | 4 ++-- builder/amazon/common/access_config.go | 4 ++-- builder/amazon/common/artifact.go | 2 +- builder/amazon/common/block_device.go | 8 +++---- builder/amazon/common/block_device_test.go | 21 +++++++++---------- builder/amazon/common/step_ami_region_copy.go | 9 ++++---- builder/amazon/common/step_create_tags.go | 2 +- .../common/step_modify_ami_attributes.go | 2 +- .../amazon/common/step_run_source_instance.go | 12 +++++------ builder/amazon/common/step_security_group.go | 4 ++-- builder/amazon/ebs/step_create_ami.go | 2 +- builder/amazon/instance/step_register_ami.go | 2 +- 13 files changed, 38 insertions(+), 39 deletions(-) diff --git a/builder/amazon/chroot/step_create_volume.go b/builder/amazon/chroot/step_create_volume.go index 40925483a..9db99163a 100644 --- a/builder/amazon/chroot/step_create_volume.go +++ b/builder/amazon/chroot/step_create_volume.go @@ -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 { diff --git a/builder/amazon/chroot/step_register_ami.go b/builder/amazon/chroot/step_register_ami.go index 5314ef0a1..8ed4df9b9 100644 --- a/builder/amazon/chroot/step_register_ami.go +++ b/builder/amazon/chroot/step_register_ami.go @@ -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 diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index 4479e0181..88bda0423 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -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 } diff --git a/builder/amazon/common/artifact.go b/builder/amazon/common/artifact.go index 7b2537072..aba2ffde4 100644 --- a/builder/amazon/common/artifact.go +++ b/builder/amazon/common/artifact.go @@ -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) diff --git a/builder/amazon/common/block_device.go b/builder/amazon/common/block_device.go index fb14a66ae..f009cd7bc 100644 --- a/builder/amazon/common/block_device.go +++ b/builder/amazon/common/block_device.go @@ -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{ diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index c69ef2efb..d76cf4d07 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -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()) } } } diff --git a/builder/amazon/common/step_ami_region_copy.go b/builder/amazon/common/step_ami_region_copy.go index 3f545284f..d19ffe5bd 100644 --- a/builder/amazon/common/step_ami_region_copy.go +++ b/builder/amazon/common/step_ami_region_copy.go @@ -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{ diff --git a/builder/amazon/common/step_create_tags.go b/builder/amazon/common/step_create_tags.go index 4750d7a08..220735bed 100644 --- a/builder/amazon/common/step_create_tags.go +++ b/builder/amazon/common/step_create_tags.go @@ -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 diff --git a/builder/amazon/common/step_modify_ami_attributes.go b/builder/amazon/common/step_modify_ami_attributes.go index ff0352a1f..df6424245 100644 --- a/builder/amazon/common/step_modify_ami_attributes.go +++ b/builder/amazon/common/step_modify_ami_attributes.go @@ -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)) diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index b94a6031c..6482b8084 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -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{ diff --git a/builder/amazon/common/step_security_group.go b/builder/amazon/common/step_security_group.go index b65ebb408..e43e866a3 100644 --- a/builder/amazon/common/step_security_group.go +++ b/builder/amazon/common/step_security_group.go @@ -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"), } diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index dff7d88b0..a3980e3ee 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -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 diff --git a/builder/amazon/instance/step_register_ami.go b/builder/amazon/instance/step_register_ami.go index f97c5df0e..dc76331f8 100644 --- a/builder/amazon/instance/step_register_ami.go +++ b/builder/amazon/instance/step_register_ami.go @@ -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