provider/aws: session.New -> session.NewSession()
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()`.
This commit is contained in:
parent
92d1cfb890
commit
6ddb8f5975
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/iam"
|
"github.com/aws/aws-sdk-go/service/iam"
|
||||||
"github.com/aws/aws-sdk-go/service/sts"
|
"github.com/aws/aws-sdk-go/service/sts"
|
||||||
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/go-cleanhttp"
|
"github.com/hashicorp/go-cleanhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +26,12 @@ func GetAccountId(iamconn *iam.IAM, stsconn *sts.STS, authProviderName string) (
|
||||||
|
|
||||||
cfg := &aws.Config{}
|
cfg := &aws.Config{}
|
||||||
setOptionalEndpoint(cfg)
|
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()
|
info, err := metadataClient.IAMInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This can be triggered when no IAM Role is assigned
|
// This can be triggered when no IAM Role is assigned
|
||||||
|
@ -114,7 +120,11 @@ func GetCredentials(key, secret, token, profile, credsfile string) *awsCredentia
|
||||||
// Real AWS should reply to a simple metadata request.
|
// Real AWS should reply to a simple metadata request.
|
||||||
// We check it actually does to ensure something else didn't just
|
// We check it actually does to ensure something else didn't just
|
||||||
// happen to be listening on the same IP:Port
|
// 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() {
|
if metadataClient.Available() {
|
||||||
providers = append(providers, &ec2rolecreds.EC2RoleProvider{
|
providers = append(providers, &ec2rolecreds.EC2RoleProvider{
|
||||||
Client: metadataClient,
|
Client: metadataClient,
|
||||||
|
|
|
@ -648,12 +648,15 @@ func getMockedAwsIamStsApi(endpoints []*iamEndpoint) (func(), *iam.IAM, *sts.STS
|
||||||
|
|
||||||
sc := awsCredentials.NewStaticCredentials("accessKey", "secretKey", "")
|
sc := awsCredentials.NewStaticCredentials("accessKey", "secretKey", "")
|
||||||
|
|
||||||
sess := session.New(&aws.Config{
|
sess, err := session.NewSession(&aws.Config{
|
||||||
Credentials: sc,
|
Credentials: sc,
|
||||||
Region: aws.String("us-east-1"),
|
Region: aws.String("us-east-1"),
|
||||||
Endpoint: aws.String(ts.URL),
|
Endpoint: aws.String(ts.URL),
|
||||||
CredentialsChainVerboseErrors: aws.Bool(true),
|
CredentialsChainVerboseErrors: aws.Bool(true),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Error creating AWS Session: %s", err))
|
||||||
|
}
|
||||||
iamConn := iam.New(sess)
|
iamConn := iam.New(sess)
|
||||||
stsConn := sts.New(sess)
|
stsConn := sts.New(sess)
|
||||||
return ts.Close, iamConn, stsConn
|
return ts.Close, iamConn, stsConn
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/aws/request"
|
"github.com/aws/aws-sdk-go/aws/request"
|
||||||
|
@ -56,6 +50,11 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/service/sns"
|
"github.com/aws/aws-sdk-go/service/sns"
|
||||||
"github.com/aws/aws-sdk-go/service/sqs"
|
"github.com/aws/aws-sdk-go/service/sqs"
|
||||||
"github.com/aws/aws-sdk-go/service/sts"
|
"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 {
|
type Config struct {
|
||||||
|
@ -178,7 +177,10 @@ func (c *Config) Client() (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up base session
|
// 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)
|
sess.Handlers.Build.PushFrontNamed(addTerraformVersionToUserAgent)
|
||||||
|
|
||||||
// Some services exist only in us-east-1, e.g. because they manage
|
// Some services exist only in us-east-1, e.g. because they manage
|
||||||
|
|
Loading…
Reference in New Issue