terraform: orphan transform should work if state is nil

This commit is contained in:
Mitchell Hashimoto 2015-02-11 17:50:07 -08:00
parent e45308fa6d
commit 2b917054da
2 changed files with 32 additions and 0 deletions

View File

@ -21,6 +21,11 @@ type OrphanTransformer struct {
}
func (t *OrphanTransformer) Transform(g *Graph) error {
if t.State == nil {
// If the entire state is nil, there can't be any orphans
return nil
}
var config *config.Config
if module := t.Module.Child(g.Path[1:]); module != nil {
config = module.Config()

View File

@ -300,6 +300,29 @@ func TestOrphanTransformer_resourceDepends(t *testing.T) {
}
}
func TestOrphanTransformer_nilState(t *testing.T) {
mod := testModule(t, "transform-orphan-basic")
g := Graph{Path: RootModulePath}
{
tf := &ConfigTransformer{Module: mod}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
}
transform := &OrphanTransformer{State: nil, Module: mod}
if err := transform.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformOrphanNilStateStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestGraphNodeOrphanModule_impl(t *testing.T) {
var _ dag.Vertex = new(graphNodeOrphanModule)
var _ dag.NamedVertex = new(graphNodeOrphanModule)
@ -342,6 +365,10 @@ module.foo (orphan)
aws_instance.web (orphan)
`
const testTransformOrphanNilStateStr = `
aws_instance.web
`
const testTransformOrphanResourceDependsStr = `
aws_instance.db (orphan)
aws_instance.web