4 "github.com/hashicorp/terraform/config/module"
5 "github.com/hashicorp/terraform/dag"
8 // ImportGraphBuilder implements GraphBuilder and is responsible for building
9 // a graph for importing resources into Terraform. This is a much, much
10 // simpler graph than a normal configuration graph.
11 type ImportGraphBuilder struct {
12 // ImportTargets are the list of resources to import.
13 ImportTargets []*ImportTarget
15 // Module is the module to add to the graph. See ImportOpts.Module.
18 // Providers is the list of providers supported.
22 // Build builds the graph according to the steps returned by Steps.
23 func (b *ImportGraphBuilder) Build(path []string) (*Graph, error) {
24 return (&BasicGraphBuilder{
27 Name: "ImportGraphBuilder",
31 // Steps returns the ordered list of GraphTransformers that must be executed
32 // to build a complete graph.
33 func (b *ImportGraphBuilder) Steps() []GraphTransformer {
34 // Get the module. If we don't have one, we just use an empty tree
35 // so that the transform still works but does nothing.
38 mod = module.NewEmptyTree()
41 // Custom factory for creating providers.
42 concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
43 return &NodeApplyableProvider{
44 NodeAbstractProvider: a,
48 steps := []GraphTransformer{
49 // Create all our resources from the configuration and state
50 &ConfigTransformer{Module: mod},
52 // Add the import steps
53 &ImportStateTransformer{Targets: b.ImportTargets},
55 TransformProviders(b.Providers, concreteProvider, mod),
57 // This validates that the providers only depend on variables
58 &ImportProviderValidateTransformer{},
60 // Close opened plugin connections
61 &CloseProviderTransformer{},
67 &TransitiveReductionTransformer{},