github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/terraform/graph_builder_destroy_plan.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/config/module"
     5  	"github.com/hashicorp/terraform/dag"
     6  )
     7  
     8  // DestroyPlanGraphBuilder implements GraphBuilder and is responsible for
     9  // planning a pure-destroy.
    10  //
    11  // Planning a pure destroy operation is simple because we can ignore most
    12  // ordering configuration and simply reverse the state.
    13  type DestroyPlanGraphBuilder struct {
    14  	// Module is the root module for the graph to build.
    15  	Module *module.Tree
    16  
    17  	// State is the current state
    18  	State *State
    19  
    20  	// Targets are resources to target
    21  	Targets []string
    22  
    23  	// Validate will do structural validation of the graph.
    24  	Validate bool
    25  }
    26  
    27  // See GraphBuilder
    28  func (b *DestroyPlanGraphBuilder) Build(path []string) (*Graph, error) {
    29  	return (&BasicGraphBuilder{
    30  		Steps:    b.Steps(),
    31  		Validate: b.Validate,
    32  		Name:     "DestroyPlanGraphBuilder",
    33  	}).Build(path)
    34  }
    35  
    36  // See GraphBuilder
    37  func (b *DestroyPlanGraphBuilder) Steps() []GraphTransformer {
    38  	concreteResource := func(a *NodeAbstractResource) dag.Vertex {
    39  		return &NodePlanDestroyableResource{
    40  			NodeAbstractResource: a,
    41  		}
    42  	}
    43  
    44  	steps := []GraphTransformer{
    45  		// Creates all the nodes represented in the state.
    46  		&StateTransformer{
    47  			Concrete: concreteResource,
    48  			State:    b.State,
    49  		},
    50  
    51  		// Attach the configuration to any resources
    52  		&AttachResourceConfigTransformer{Module: b.Module},
    53  
    54  		// Destruction ordering. We require this only so that
    55  		// targeting below will prune the correct things.
    56  		&DestroyEdgeTransformer{Module: b.Module, State: b.State},
    57  
    58  		// Target. Note we don't set "Destroy: true" here since we already
    59  		// created proper destroy ordering.
    60  		&TargetsTransformer{Targets: b.Targets},
    61  
    62  		// Single root
    63  		&RootTransformer{},
    64  	}
    65  
    66  	return steps
    67  }