terraform: orphan transform should work if state is nil
This commit is contained in:
parent
e45308fa6d
commit
2b917054da
|
@ -21,6 +21,11 @@ type OrphanTransformer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *OrphanTransformer) Transform(g *Graph) error {
|
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
|
var config *config.Config
|
||||||
if module := t.Module.Child(g.Path[1:]); module != nil {
|
if module := t.Module.Child(g.Path[1:]); module != nil {
|
||||||
config = module.Config()
|
config = module.Config()
|
||||||
|
|
|
@ -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) {
|
func TestGraphNodeOrphanModule_impl(t *testing.T) {
|
||||||
var _ dag.Vertex = new(graphNodeOrphanModule)
|
var _ dag.Vertex = new(graphNodeOrphanModule)
|
||||||
var _ dag.NamedVertex = new(graphNodeOrphanModule)
|
var _ dag.NamedVertex = new(graphNodeOrphanModule)
|
||||||
|
@ -342,6 +365,10 @@ module.foo (orphan)
|
||||||
aws_instance.web (orphan)
|
aws_instance.web (orphan)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testTransformOrphanNilStateStr = `
|
||||||
|
aws_instance.web
|
||||||
|
`
|
||||||
|
|
||||||
const testTransformOrphanResourceDependsStr = `
|
const testTransformOrphanResourceDependsStr = `
|
||||||
aws_instance.db (orphan)
|
aws_instance.db (orphan)
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
|
|
Loading…
Reference in New Issue