2015-01-26 22:17:52 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// OrphanTransformer is a GraphTransformer that adds orphans to the
|
|
|
|
// graph. This transformer adds both resource and module orphans.
|
|
|
|
type OrphanTransformer struct {
|
|
|
|
State *ModuleState
|
|
|
|
Config *config.Config
|
|
|
|
}
|
|
|
|
|
2015-01-26 23:23:27 -06:00
|
|
|
func (t *OrphanTransformer) Transform(g *Graph) error {
|
2015-01-26 22:17:52 -06:00
|
|
|
// Get the orphans from our configuration. This will only get resources.
|
|
|
|
orphans := t.State.Orphans(t.Config)
|
|
|
|
if len(orphans) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go over each orphan and add it to the graph.
|
|
|
|
for _, k := range orphans {
|
2015-01-26 23:23:27 -06:00
|
|
|
g.ConnectTo(
|
|
|
|
g.Add(&graphNodeOrphanResource{ResourceName: k}),
|
|
|
|
t.State.Resources[k].Dependencies)
|
2015-01-26 22:17:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: modules
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// graphNodeOrphan is the graph vertex representing an orphan resource..
|
|
|
|
type graphNodeOrphanResource struct {
|
|
|
|
ResourceName string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeOrphanResource) Name() string {
|
|
|
|
return fmt.Sprintf("%s (orphan)", n.ResourceName)
|
|
|
|
}
|