providers/aws: style nitpick

This commit is contained in:
Mitchell Hashimoto 2015-06-28 22:46:49 -07:00
parent 2a5ed6c847
commit 93cedc7ec1
2 changed files with 17 additions and 10 deletions

View File

@ -76,8 +76,8 @@ func (c *Config) Client() (interface{}, error) {
client.region = c.Region client.region = c.Region
log.Println("[INFO] Building AWS auth structure") log.Println("[INFO] Building AWS auth structure")
// We fetched all credential sources in Provider. // We fetched all credential sources in Provider. If they are
// If it is available, it is stored in c. // available, they'll already be in c. See Provider definition.
creds := credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, c.Token) creds := credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, c.Token)
awsConfig := &aws.Config{ awsConfig := &aws.Config{
Credentials: creds, Credentials: creds,

View File

@ -14,21 +14,28 @@ func Provider() terraform.ResourceProvider {
// TODO: Move the validation to this, requires conditional schemas // TODO: Move the validation to this, requires conditional schemas
// TODO: Move the configuration to this, requires validation // TODO: Move the configuration to this, requires validation
// Prepare to handle external sources of credentials. // These variables are closed within the `getCreds` function below.
// Static credentials are intentionally omitted; // This function is responsible for reading credentials from the
// this is used when no static credentials are provided. // environment in the case that they're not explicitly specified
// in the Terraform configuration.
//
// By using the getCreds function here instead of making the default
// empty, we avoid asking for input on credentials if they're available
// in the environment.
var credVal credentials.Value
var credErr error
var once sync.Once
getCreds := func() {
creds := credentials.NewChainCredentials([]credentials.Provider{ creds := credentials.NewChainCredentials([]credentials.Provider{
&credentials.EnvProvider{}, &credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{}, &credentials.SharedCredentialsProvider{},
&credentials.EC2RoleProvider{}, &credentials.EC2RoleProvider{},
}) })
var credVal credentials.Value
var credErr error
var once sync.Once
getCreds := func() {
credVal, credErr = creds.Get() credVal, credErr = creds.Get()
} }
// The actual provider
return &schema.Provider{ return &schema.Provider{
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"access_key": &schema.Schema{ "access_key": &schema.Schema{