github.com/bpineau/terraform@v0.8.0-rc1.0.20161126184705-a8886012d185/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 Name: "ImportGraphBuilder", 27 }).Build(path) 28 } 29 30 // Steps returns the ordered list of GraphTransformers that must be executed 31 // to build a complete graph. 32 func (b *ImportGraphBuilder) Steps() []GraphTransformer { 33 // Get the module. If we don't have one, we just use an empty tree 34 // so that the transform still works but does nothing. 35 mod := b.Module 36 if mod == nil { 37 mod = module.NewEmptyTree() 38 } 39 40 // Custom factory for creating providers. 41 providerFactory := func(name string, path []string) GraphNodeProvider { 42 return &NodeApplyableProvider{ 43 NameValue: name, 44 PathValue: path, 45 } 46 } 47 48 steps := []GraphTransformer{ 49 // Create all our resources from the configuration and state 50 &ConfigTransformerOld{Module: mod}, 51 52 // Add the import steps 53 &ImportStateTransformer{Targets: b.ImportTargets}, 54 55 // Provider-related transformations 56 &MissingProviderTransformer{Providers: b.Providers, Factory: providerFactory}, 57 &ProviderTransformer{}, 58 &DisableProviderTransformerOld{}, 59 &PruneProviderTransformer{}, 60 &AttachProviderConfigTransformer{Module: mod}, 61 62 // This validates that the providers only depend on variables 63 &ImportProviderValidateTransformer{}, 64 65 // Single root 66 &RootTransformer{}, 67 68 // Optimize 69 &TransitiveReductionTransformer{}, 70 } 71 72 return steps 73 }