providers/aws: proper DefaultFunc to return nil if no env

This commit is contained in:
Mitchell Hashimoto 2014-09-09 21:46:50 -07:00
parent 281b59533d
commit 2317f7ea9b
1 changed files with 19 additions and 15 deletions

View File

@ -19,27 +19,21 @@ func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"region": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: func() (interface{}, error) {
return os.Getenv("AWS_REGION"), nil
},
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AWS_REGION"),
},
"access_key": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: func() (interface{}, error) {
return os.Getenv("AWS_ACCESS_KEY"), nil
},
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AWS_ACCESS_KEY"),
},
"secret_key": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: func() (interface{}, error) {
return os.Getenv("AWS_SECRET_KEY"), nil
},
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("AWS_SECRET_KEY"),
},
},
@ -50,3 +44,13 @@ func Provider() *schema.Provider {
},
}
}
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
return func() (interface{}, error) {
if v := os.Getenv(k); v != "" {
return v, nil
}
return nil, nil
}
}