diff --git a/terraform/context.go b/terraform/context.go index e489ae2676..6336b2bcd0 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -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) diff --git a/terraform/context_test.go b/terraform/context_test.go index 877ff00cc0..7aba50395b 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -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")