provider/aws: Improve validation of configs

This commit is contained in:
Armon Dadgar 2014-07-23 15:13:36 -04:00
parent 4b1d9b5b2f
commit 5065aff158
1 changed files with 23 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package aws
import ( import (
"log" "log"
"os"
"github.com/hashicorp/terraform/helper/config" "github.com/hashicorp/terraform/helper/config"
"github.com/hashicorp/terraform/helper/multierror" "github.com/hashicorp/terraform/helper/multierror"
@ -26,14 +27,30 @@ type ResourceProvider struct {
} }
func (p *ResourceProvider) Validate(c *terraform.ResourceConfig) ([]string, []error) { func (p *ResourceProvider) Validate(c *terraform.ResourceConfig) ([]string, []error) {
v := &config.Validator{ type param struct {
Optional: []string{ env string
"access_key", key string
"secret_key", }
"region", params := []param{
}, {"AWS_REGION", "region"},
{"AWS_ACCESS_KEY", "access_key"},
{"AWS_SECRET_KEY", "secret_key"},
} }
var optional []string
var required []string
for _, p := range params {
if v := os.Getenv(p.env); v != "" {
optional = append(optional, p.key)
} else {
required = append(required, p.key)
}
}
v := &config.Validator{
Required: required,
Optional: optional,
}
return v.Validate(c) return v.Validate(c)
} }