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 (
"log"
"os"
"github.com/hashicorp/terraform/helper/config"
"github.com/hashicorp/terraform/helper/multierror"
@ -26,14 +27,30 @@ type ResourceProvider struct {
}
func (p *ResourceProvider) Validate(c *terraform.ResourceConfig) ([]string, []error) {
v := &config.Validator{
Optional: []string{
"access_key",
"secret_key",
"region",
},
type param struct {
env string
key string
}
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)
}