]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package terraform |
2 | ||
3 | import ( | |
4 | "github.com/hashicorp/terraform/config/module" | |
5 | "github.com/hashicorp/terraform/dag" | |
6 | ) | |
7 | ||
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 | |
14 | ||
15 | // Module is the module to add to the graph. See ImportOpts.Module. | |
16 | Module *module.Tree | |
17 | ||
18 | // Providers is the list of providers supported. | |
19 | Providers []string | |
20 | } | |
21 | ||
22 | // Build builds the graph according to the steps returned by Steps. | |
23 | func (b *ImportGraphBuilder) Build(path []string) (*Graph, error) { | |
24 | return (&BasicGraphBuilder{ | |
25 | Steps: b.Steps(), | |
26 | Validate: true, | |
27 | Name: "ImportGraphBuilder", | |
28 | }).Build(path) | |
29 | } | |
30 | ||
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. | |
36 | mod := b.Module | |
37 | if mod == nil { | |
38 | mod = module.NewEmptyTree() | |
39 | } | |
40 | ||
41 | // Custom factory for creating providers. | |
42 | concreteProvider := func(a *NodeAbstractProvider) dag.Vertex { | |
43 | return &NodeApplyableProvider{ | |
44 | NodeAbstractProvider: a, | |
45 | } | |
46 | } | |
47 | ||
48 | steps := []GraphTransformer{ | |
49 | // Create all our resources from the configuration and state | |
50 | &ConfigTransformer{Module: mod}, | |
51 | ||
52 | // Add the import steps | |
53 | &ImportStateTransformer{Targets: b.ImportTargets}, | |
54 | ||
55 | // Provider-related transformations | |
56 | &MissingProviderTransformer{Providers: b.Providers, Concrete: concreteProvider}, | |
57 | &ProviderTransformer{}, | |
58 | &DisableProviderTransformer{}, | |
59 | &ParentProviderTransformer{}, | |
60 | &AttachProviderConfigTransformer{Module: mod}, | |
61 | ||
62 | // This validates that the providers only depend on variables | |
63 | &ImportProviderValidateTransformer{}, | |
64 | ||
65 | // Close opened plugin connections | |
66 | &CloseProviderTransformer{}, | |
67 | ||
68 | // Single root | |
69 | &RootTransformer{}, | |
70 | ||
71 | // Optimize | |
72 | &TransitiveReductionTransformer{}, | |
73 | } | |
74 | ||
75 | return steps | |
76 | } |