terraform: validate providers even without config block [GH-284]

This commit is contained in:
Mitchell Hashimoto 2014-09-09 17:38:30 -07:00
parent 267a125a07
commit a53faa2fff
4 changed files with 28 additions and 3 deletions

View File

@ -1,6 +1,8 @@
## 0.2.3 (unreleased)
BUG FIXES:
* core: Providers are validated even without a `provider` block. [GH-284]
## 0.2.2 (September 9, 2014)

View File

@ -933,11 +933,12 @@ func (c *Context) validateWalkFn(rws *[]string, res *[]error) depgraph.WalkFunc
}
case *GraphNodeResourceProvider:
if rn.Config == nil {
return nil
var raw *config.RawConfig
if rn.Config != nil {
raw = rn.Config.RawConfig
}
rc := NewResourceConfig(rn.Config.RawConfig)
rc := NewResourceConfig(raw)
for k, p := range rn.Providers {
log.Printf("[INFO] Validating provider: %s", k)

View File

@ -121,6 +121,27 @@ func TestContextValidate_providerConfig_bad(t *testing.T) {
}
}
func TestContextValidate_providerConfig_badEmpty(t *testing.T) {
config := testConfig(t, "validate-bad-pc-empty")
p := testProvider("aws")
c := testContext(t, &ContextOpts{
Config: config,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
p.ValidateReturnErrors = []error{fmt.Errorf("bad")}
w, e := c.Validate()
if len(w) > 0 {
t.Fatalf("bad: %#v", w)
}
if len(e) == 0 {
t.Fatalf("bad: %#v", e)
}
}
func TestContextValidate_providerConfig_good(t *testing.T) {
config := testConfig(t, "validate-bad-pc")
p := testProvider("aws")

View File

@ -0,0 +1 @@
resource "aws_instance" "test" {}