Skip to content

Commit

Permalink
Compatibility layer with goamz functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Simko committed Feb 27, 2015
1 parent b9d4092 commit 4be64da
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions builtin/providers/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package aws
import (
"fmt"
"log"
"os"
"strings"
"time"
"unicode"

"github.com/hashicorp/terraform/helper/multierror"
Expand Down Expand Up @@ -40,8 +42,7 @@ func (c *Config) Client() (interface{}, error) {
var errs []error

log.Println("[INFO] Detecting AWS creds via aws-sdk-go")
credsProvider := awsGo.DetectCreds(c.AccessKey, c.SecretKey, "")
_, err := credsProvider.Credentials()
credsProvider, err := c.getCredentialsProvider()
if err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -105,6 +106,26 @@ func (c *Config) AWSAuth() (aws.Auth, error) {
return auth, err
}

func (c *Config) getCredentialsProvider() (awsGo.CredentialsProvider, error) {
// Backward compatibility
if v := os.Getenv("AWS_SECURITY_TOKEN"); v != "" {
os.Setenv("AWS_SESSION_TOKEN", v)
}

if filePath := os.Getenv("AWS_CREDENTIAL_FILE"); filePath != "" {
profileName := os.Getenv("AWS_PROFILE")

// TODO: Could be a variable but there's no standardized name for it
expiry := 10 * time.Minute

return awsGo.ProfileCreds(filePath, profileName, expiry)
}

provider := awsGo.DetectCreds(c.AccessKey, c.SecretKey, "")
_, err := provider.Credentials()
return provider, err
}

// IsValidRegion returns true if the configured region is a valid AWS
// region and false if it's not
func (c *Config) IsValidRegion() bool {
Expand Down

0 comments on commit 4be64da

Please sign in to comment.