Skip to content

Commit

Permalink
provider/aws: session.New -> session.NewSession()
Browse files Browse the repository at this point in the history
Version 1.3.1 deprecates use of `session.New()` in favour of
`session.NewSession()`, which also returns an error. This commit updates
the various call sites previously making use of `session.New()`.
  • Loading branch information
jen20 committed Aug 8, 2016
1 parent 92d1cfb commit 6ddb8f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
14 changes: 12 additions & 2 deletions builtin/providers/aws/auth_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/go-cleanhttp"
)

Expand All @@ -25,7 +26,12 @@ func GetAccountId(iamconn *iam.IAM, stsconn *sts.STS, authProviderName string) (

cfg := &aws.Config{}
setOptionalEndpoint(cfg)
metadataClient := ec2metadata.New(session.New(cfg))
sess, err := session.NewSession(cfg)
if err != nil {
return "", errwrap.Wrapf("Error creating AWS session: %s", err)
}

metadataClient := ec2metadata.New(sess)
info, err := metadataClient.IAMInfo()
if err != nil {
// This can be triggered when no IAM Role is assigned
Expand Down Expand Up @@ -114,7 +120,11 @@ func GetCredentials(key, secret, token, profile, credsfile string) *awsCredentia
// Real AWS should reply to a simple metadata request.
// We check it actually does to ensure something else didn't just
// happen to be listening on the same IP:Port
metadataClient := ec2metadata.New(session.New(cfg))
sess, err := session.NewSession(cfg)
if err != nil {
log.Printf("[INFO] Error creating AWS session for metadata client: %s", err)
}
metadataClient := ec2metadata.New(sess)
if metadataClient.Available() {
providers = append(providers, &ec2rolecreds.EC2RoleProvider{
Client: metadataClient,
Expand Down
5 changes: 4 additions & 1 deletion builtin/providers/aws/auth_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,15 @@ func getMockedAwsIamStsApi(endpoints []*iamEndpoint) (func(), *iam.IAM, *sts.STS

sc := awsCredentials.NewStaticCredentials("accessKey", "secretKey", "")

sess := session.New(&aws.Config{
sess, err := session.NewSession(&aws.Config{
Credentials: sc,
Region: aws.String("us-east-1"),
Endpoint: aws.String(ts.URL),
CredentialsChainVerboseErrors: aws.Bool(true),
})
if err != nil {
panic(fmt.Sprintf("Error creating AWS Session: %s", err))
}
iamConn := iam.New(sess)
stsConn := sts.New(sess)
return ts.Close, iamConn, stsConn
Expand Down
18 changes: 10 additions & 8 deletions builtin/providers/aws/config.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
package aws

import (
"crypto/tls"
"fmt"
"log"
"net/http"
"strings"

"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/terraform"

"crypto/tls"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
Expand Down Expand Up @@ -56,6 +50,11 @@ import (
"github.com/aws/aws-sdk-go/service/sns"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/terraform"
)

type Config struct {
Expand Down Expand Up @@ -178,7 +177,10 @@ func (c *Config) Client() (interface{}, error) {
}

// Set up base session
sess := session.New(awsConfig)
sess, err := session.NewSession(awsConfig)
if err != nil {
return nil, errwrap.Wrapf("Error creating AWS session: %s", err)
}
sess.Handlers.Build.PushFrontNamed(addTerraformVersionToUserAgent)

// Some services exist only in us-east-1, e.g. because they manage
Expand Down

0 comments on commit 6ddb8f5

Please sign in to comment.