terraform: don't validate tainted resources
This commit is contained in:
parent
6e7d23d612
commit
ecafcfa682
|
@ -1046,23 +1046,24 @@ func (c *walkContext) validateWalkFn() depgraph.WalkFunc {
|
|||
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 {
|
||||
return nil
|
||||
}
|
||||
if rn.Resource.Flags&FlagTainted != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the resouce name doesn't match the name regular
|
||||
// expression, show a warning.
|
||||
if rn.Config != nil {
|
||||
if !config.NameRegexp.Match([]byte(rn.Config.Name)) {
|
||||
l.Lock()
|
||||
meta.Warns = append(meta.Warns, fmt.Sprintf(
|
||||
"%s: module name can only contain letters, numbers, "+
|
||||
"dashes, and underscores.\n"+
|
||||
"This will be an error in Terraform 0.4",
|
||||
rn.Resource.Id))
|
||||
l.Unlock()
|
||||
}
|
||||
if !config.NameRegexp.Match([]byte(rn.Config.Name)) {
|
||||
l.Lock()
|
||||
meta.Warns = append(meta.Warns, fmt.Sprintf(
|
||||
"%s: module name can only contain letters, numbers, "+
|
||||
"dashes, and underscores.\n"+
|
||||
"This will be an error in Terraform 0.4",
|
||||
rn.Resource.Id))
|
||||
l.Unlock()
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Validating resource: %s", rn.Resource.Id)
|
||||
|
|
|
@ -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) {
|
||||
m := testModule(t, "validate-bad-pc")
|
||||
p := testProvider("aws")
|
||||
|
|
Loading…
Reference in New Issue