File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package aws
22
33import (
44 "log"
5+ "os"
56
67 "github.com/hashicorp/terraform/helper/config"
78 "github.com/hashicorp/terraform/helper/multierror"
@@ -26,14 +27,30 @@ type ResourceProvider struct {
2627}
2728
2829func (p * ResourceProvider ) Validate (c * terraform.ResourceConfig ) ([]string , []error ) {
29- v := & config.Validator {
30- Optional : []string {
31- "access_key" ,
32- "secret_key" ,
33- "region" ,
34- },
30+ type param struct {
31+ env string
32+ key string
33+ }
34+ params := []param {
35+ {"AWS_REGION" , "region" },
36+ {"AWS_ACCESS_KEY" , "access_key" },
37+ {"AWS_SECRET_KEY" , "secret_key" },
38+ }
39+
40+ var optional []string
41+ var required []string
42+ for _ , p := range params {
43+ if v := os .Getenv (p .env ); v != "" {
44+ optional = append (optional , p .key )
45+ } else {
46+ required = append (required , p .key )
47+ }
3548 }
3649
50+ v := & config.Validator {
51+ Required : required ,
52+ Optional : optional ,
53+ }
3754 return v .Validate (c )
3855}
3956
You can’t perform that action at this time.
0 commit comments