terraform: don't validate tainted resources

This commit is contained in:
Mitchell Hashimoto 2014-10-11 16:02:07 -07:00
parent 6e7d23d612
commit ecafcfa682
2 changed files with 54 additions and 11 deletions

View File

@ -1046,14 +1046,16 @@ func (c *walkContext) validateWalkFn() depgraph.WalkFunc {
return nil return nil
} }
// Don't validate orphans since they never have a config // Don't validate orphans or tainted since they never have a config
if rn.Resource.Flags&FlagOrphan != 0 { if rn.Resource.Flags&FlagOrphan != 0 {
return nil return nil
} }
if rn.Resource.Flags&FlagTainted != 0 {
return nil
}
// If the resouce name doesn't match the name regular // If the resouce name doesn't match the name regular
// expression, show a warning. // expression, show a warning.
if rn.Config != nil {
if !config.NameRegexp.Match([]byte(rn.Config.Name)) { if !config.NameRegexp.Match([]byte(rn.Config.Name)) {
l.Lock() l.Lock()
meta.Warns = append(meta.Warns, fmt.Sprintf( meta.Warns = append(meta.Warns, fmt.Sprintf(
@ -1063,7 +1065,6 @@ func (c *walkContext) validateWalkFn() depgraph.WalkFunc {
rn.Resource.Id)) rn.Resource.Id))
l.Unlock() l.Unlock()
} }
}
log.Printf("[INFO] Validating resource: %s", rn.Resource.Id) log.Printf("[INFO] Validating resource: %s", rn.Resource.Id)
ws, es := rn.Resource.Provider.ValidateResource( ws, es := rn.Resource.Provider.ValidateResource(

View File

@ -211,6 +211,48 @@ func TestContextValidate_orphans(t *testing.T) {
} }
} }
func TestContextValidate_tainted(t *testing.T) {
p := testProvider("aws")
m := testModule(t, "validate-good")
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Tainted: []*InstanceState{
&InstanceState{
ID: "bar",
},
},
},
},
},
},
}
c := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: state,
})
p.ValidateResourceFn = func(
t string, c *ResourceConfig) ([]string, []error) {
return nil, c.CheckSet([]string{"foo"})
}
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_bad(t *testing.T) { func TestContextValidate_providerConfig_bad(t *testing.T) {
m := testModule(t, "validate-bad-pc") m := testModule(t, "validate-bad-pc")
p := testProvider("aws") p := testProvider("aws")