From ca9a5daf29e66d873b9653e2b3c6186db031e4d6 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 1 Mar 2019 14:28:16 -0800 Subject: [PATCH 1/3] fix proxy and tls --- builder/amazon/common/access_config.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index ed6910b34..adf0e053e 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -14,7 +14,6 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" cleanhttp "github.com/hashicorp/go-cleanhttp" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/template/interpolate" vaultapi "github.com/hashicorp/vault/api" ) @@ -72,13 +71,14 @@ func (c *AccessConfig) Session() (*session.Session, error) { config = config.WithEndpoint(c.CustomEndpointEc2) } + config = config.WithHTTPClient(cleanhttp.DefaultClient()) + transport := config.HTTPClient.Transport.(*http.Transport) if c.InsecureSkipTLSVerify { - config := config.WithHTTPClient(cleanhttp.DefaultClient()) - transport := config.HTTPClient.Transport.(*http.Transport) transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, } } + transport.Proxy = http.ProxyFromEnvironment opts := session.Options{ SharedConfigState: session.SharedConfigEnable, @@ -210,9 +210,7 @@ func (c *AccessConfig) NewEC2Connection() (ec2iface.EC2API, error) { return nil, err } - ec2conn := ec2.New(sess, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(sess) return ec2conn, nil } From 0ed57a37a3d8d3642e54f1be8a0eef758a1f3147 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 4 Mar 2019 16:19:39 -0800 Subject: [PATCH 2/3] dont overwrite session config in ebs builder --- builder/amazon/ebs/builder.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 0cd29bdce..3f9db2f6e 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -93,9 +93,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, err } - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) // Setup the state bag and initial state for the steps state := new(multistep.BasicStateBag) From 3ed9fe6dee608dbb77dcab44cbcd57db70561c94 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 4 Mar 2019 16:22:52 -0800 Subject: [PATCH 3/3] remove unused imports remove HttpClientWithEnvironmentProxy from amazon builders; let access config handle it --- builder/amazon/chroot/builder.go | 6 +----- builder/amazon/common/artifact.go | 4 +--- builder/amazon/common/step_ami_region_copy.go | 4 +--- builder/amazon/common/step_create_tags.go | 4 +--- builder/amazon/common/step_deregister_ami.go | 4 +--- builder/amazon/common/step_modify_ami_attributes.go | 7 ++----- builder/amazon/ebs/builder.go | 2 -- builder/amazon/ebssurrogate/builder.go | 6 +----- builder/amazon/ebsvolume/builder.go | 6 +----- builder/amazon/instance/builder.go | 6 +----- post-processor/amazon-import/post-processor.go | 5 +---- 11 files changed, 11 insertions(+), 43 deletions(-) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index c85878cd6..78072ecd5 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -9,11 +9,9 @@ import ( "log" "runtime" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -192,9 +190,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe if err != nil { return nil, err } - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) wrappedCommand := func(command string) (string, error) { ctx := b.config.ctx diff --git a/builder/amazon/common/artifact.go b/builder/amazon/common/artifact.go index 70b570691..90d7dec10 100644 --- a/builder/amazon/common/artifact.go +++ b/builder/amazon/common/artifact.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/packer" ) @@ -71,8 +70,7 @@ func (a *Artifact) Destroy() error { log.Printf("Deregistering image ID (%s) from region (%s)", imageId, region) regionConn := ec2.New(a.Session, &aws.Config{ - Region: aws.String(region), - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), + Region: aws.String(region), }) // Get image metadata diff --git a/builder/amazon/common/step_ami_region_copy.go b/builder/amazon/common/step_ami_region_copy.go index 45c97e985..380c88d8d 100644 --- a/builder/amazon/common/step_ami_region_copy.go +++ b/builder/amazon/common/step_ami_region_copy.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -104,8 +103,7 @@ func amiRegionCopy(ctx context.Context, state multistep.StateBag, config *Access } regionconn := ec2.New(session.Copy(&aws.Config{ - Region: aws.String(target), - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), + Region: aws.String(target), })) 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 484ca1c27..95a736a6b 100644 --- a/builder/amazon/common/step_create_tags.go +++ b/builder/amazon/common/step_create_tags.go @@ -9,7 +9,6 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" retry "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" @@ -36,8 +35,7 @@ func (s *StepCreateTags) Run(_ context.Context, state multistep.StateBag) multis ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami)) regionConn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - Region: aws.String(region), + Region: aws.String(region), }) // Retrieve image list for given AMI diff --git a/builder/amazon/common/step_deregister_ami.go b/builder/amazon/common/step_deregister_ami.go index 7f2223921..69d623ba6 100644 --- a/builder/amazon/common/step_deregister_ami.go +++ b/builder/amazon/common/step_deregister_ami.go @@ -6,7 +6,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -38,8 +37,7 @@ func (s *StepDeregisterAMI) Run(_ context.Context, state multistep.StateBag) mul } regionconn := ec2.New(session.Copy(&aws.Config{ - Region: aws.String(region), - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), + Region: aws.String(region), })) resp, err := regionconn.DescribeImages(&ec2.DescribeImagesInput{ diff --git a/builder/amazon/common/step_modify_ami_attributes.go b/builder/amazon/common/step_modify_ami_attributes.go index 0fd9d644f..234e1762a 100644 --- a/builder/amazon/common/step_modify_ami_attributes.go +++ b/builder/amazon/common/step_modify_ami_attributes.go @@ -7,7 +7,6 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" @@ -146,8 +145,7 @@ func (s *StepModifyAMIAttributes) Run(_ context.Context, state multistep.StateBa for region, ami := range amis { ui.Say(fmt.Sprintf("Modifying attributes on AMI (%s)...", ami)) regionConn := ec2.New(session, &aws.Config{ - Region: aws.String(region), - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), + Region: aws.String(region), }) for name, input := range options { ui.Message(fmt.Sprintf("Modifying: %s", name)) @@ -167,8 +165,7 @@ func (s *StepModifyAMIAttributes) Run(_ context.Context, state multistep.StateBa for _, snapshot := range region_snapshots { ui.Say(fmt.Sprintf("Modifying attributes on snapshot (%s)...", snapshot)) regionConn := ec2.New(session, &aws.Config{ - Region: aws.String(region), - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), + Region: aws.String(region), }) for name, input := range snapshotOptions { ui.Message(fmt.Sprintf("Modifying: %s", name)) diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 3f9db2f6e..c6a730a6c 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -9,11 +9,9 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index f70482106..4826e36a4 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -7,11 +7,9 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" @@ -107,9 +105,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe if err != nil { return nil, err } - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) // Setup the state bag and initial state for the steps state := new(multistep.BasicStateBag) diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index 95801c80e..239ef4891 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -6,11 +6,9 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" @@ -96,9 +94,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe if err != nil { return nil, err } - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) // Setup the state bag and initial state for the steps state := new(multistep.BasicStateBag) diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 5eef95538..8d0e2c212 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -9,11 +9,9 @@ import ( "os" "strings" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" @@ -177,9 +175,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe if err != nil { return nil, err } - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) // Setup the state bag and initial state for the steps state := new(multistep.BasicStateBag) diff --git a/post-processor/amazon-import/post-processor.go b/post-processor/amazon-import/post-processor.go index 361ad19ff..58e91c9e8 100644 --- a/post-processor/amazon-import/post-processor.go +++ b/post-processor/amazon-import/post-processor.go @@ -12,7 +12,6 @@ import ( "github.com/aws/aws-sdk-go/service/s3/s3manager" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" - commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/template/interpolate" @@ -170,9 +169,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac // Call EC2 image import process log.Printf("Calling EC2 to import from s3://%s/%s", p.config.S3Bucket, p.config.S3Key) - ec2conn := ec2.New(session, &aws.Config{ - HTTPClient: commonhelper.HttpClientWithEnvironmentProxy(), - }) + ec2conn := ec2.New(session) params := &ec2.ImportImageInput{ DiskContainers: []*ec2.ImageDiskContainer{ {