github.com/ljosa/terraform@v0.7.0-rc2.0.20160617205345-fe540b408f59/terraform/graph_builder_import.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/config/module"
     5  )
     6  
     7  // ImportGraphBuilder implements GraphBuilder and is responsible for building
     8  // a graph for importing resources into Terraform. This is a much, much
     9  // simpler graph than a normal configuration graph.
    10  type ImportGraphBuilder struct {
    11  	// ImportTargets are the list of resources to import.
    12  	ImportTargets []*ImportTarget
    13  
    14  	// Module is the module to add to the graph. See ImportOpts.Module.
    15  	Module *module.Tree
    16  
    17  	// Providers is the list of providers supported.
    18  	Providers []string
    19  }
    20  
    21  // Build builds the graph according to the steps returned by Steps.
    22  func (b *ImportGraphBuilder) Build(path []string) (*Graph, error) {
    23  	return (&BasicGraphBuilder{
    24  		Steps:    b.Steps(),
    25  		Validate: true,
    26  	}).Build(path)
    27  }
    28  
    29  // Steps returns the ordered list of GraphTransformers that must be executed
    30  // to build a complete graph.
    31  func (b *ImportGraphBuilder) Steps() []GraphTransformer {
    32  	// Get the module. If we don't have one, we just use an empty tree
    33  	// so that the transform still works but does nothing.
    34  	mod := b.Module
    35  	if mod == nil {
    36  		mod = module.NewEmptyTree()
    37  	}
    38  
    39  	steps := []GraphTransformer{
    40  		// Create all our resources from the configuration and state
    41  		&ConfigTransformer{Module: mod},
    42  
    43  		// Add the import steps
    44  		&ImportStateTransformer{Targets: b.ImportTargets},
    45  
    46  		// Provider-related transformations
    47  		&MissingProviderTransformer{Providers: b.Providers},
    48  		&ProviderTransformer{},
    49  		&DisableProviderTransformer{},
    50  		&PruneProviderTransformer{},
    51  
    52  		// Single root
    53  		&RootTransformer{},
    54  
    55  		// Insert nodes to close opened plugin connections
    56  		&CloseProviderTransformer{},
    57  
    58  		// Optimize
    59  		&TransitiveReductionTransformer{},
    60  	}
    61  
    62  	return steps
    63  }