terraform: ValidateResource is called
This commit is contained in:
parent
6508edaba9
commit
ed57fe7083
|
@ -451,7 +451,31 @@ func (c *Context) validateWalkFn(rws *[]string, res *[]error) depgraph.WalkFunc
|
||||||
|
|
||||||
switch rn := n.Meta.(type) {
|
switch rn := n.Meta.(type) {
|
||||||
case *GraphNodeResource:
|
case *GraphNodeResource:
|
||||||
|
if rn.Resource == nil {
|
||||||
|
panic("resource should never be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it doesn't have a provider, that is a different problem
|
||||||
|
if rn.Resource.Provider == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ws, es := rn.Resource.Provider.ValidateResource(
|
||||||
|
rn.Type, rn.Resource.Config)
|
||||||
|
for i, w := range ws {
|
||||||
|
ws[i] = fmt.Sprintf("'%s' warning: %s", rn.Resource.Id, w)
|
||||||
|
}
|
||||||
|
for i, e := range es {
|
||||||
|
es[i] = fmt.Errorf("'%s' error: %s", rn.Resource.Id, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
*rws = append(*rws, ws...)
|
||||||
|
*res = append(*res, es...)
|
||||||
case *GraphNodeResourceProvider:
|
case *GraphNodeResourceProvider:
|
||||||
|
if rn.Config == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
rc := NewResourceConfig(rn.Config.RawConfig)
|
rc := NewResourceConfig(rn.Config.RawConfig)
|
||||||
|
|
||||||
for k, p := range rn.Providers {
|
for k, p := range rn.Providers {
|
||||||
|
|
|
@ -77,6 +77,27 @@ func TestContextValidate_providerConfig_good(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextValidate_resourceConfig_bad(t *testing.T) {
|
||||||
|
config := testConfig(t, "validate-bad-rc")
|
||||||
|
p := testProvider("aws")
|
||||||
|
c := testContext(t, &ContextOpts{
|
||||||
|
Config: config,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
p.ValidateResourceReturnErrors = []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_requiredVar(t *testing.T) {
|
func TestContextValidate_requiredVar(t *testing.T) {
|
||||||
config := testConfig(t, "validate-required-var")
|
config := testConfig(t, "validate-required-var")
|
||||||
c := testContext(t, &ContextOpts{
|
c := testContext(t, &ContextOpts{
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
resource "aws_instance" "test" {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
Loading…
Reference in New Issue