]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/terraform/terraform/graph_builder_import.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / graph_builder_import.go
1 package terraform
2
3 import (
4 "github.com/hashicorp/terraform/addrs"
5 "github.com/hashicorp/terraform/configs"
6 "github.com/hashicorp/terraform/dag"
7 "github.com/hashicorp/terraform/tfdiags"
8 )
9
10 // ImportGraphBuilder implements GraphBuilder and is responsible for building
11 // a graph for importing resources into Terraform. This is a much, much
12 // simpler graph than a normal configuration graph.
13 type ImportGraphBuilder struct {
14 // ImportTargets are the list of resources to import.
15 ImportTargets []*ImportTarget
16
17 // Module is a configuration to build the graph from. See ImportOpts.Config.
18 Config *configs.Config
19
20 // Components is the factory for our available plugin components.
21 Components contextComponentFactory
22
23 // Schemas is the repository of schemas we will draw from to analyse
24 // the configuration.
25 Schemas *Schemas
26 }
27
28 // Build builds the graph according to the steps returned by Steps.
29 func (b *ImportGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) {
30 return (&BasicGraphBuilder{
31 Steps: b.Steps(),
32 Validate: true,
33 Name: "ImportGraphBuilder",
34 }).Build(path)
35 }
36
37 // Steps returns the ordered list of GraphTransformers that must be executed
38 // to build a complete graph.
39 func (b *ImportGraphBuilder) Steps() []GraphTransformer {
40 // Get the module. If we don't have one, we just use an empty tree
41 // so that the transform still works but does nothing.
42 config := b.Config
43 if config == nil {
44 config = configs.NewEmptyConfig()
45 }
46
47 // Custom factory for creating providers.
48 concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
49 return &NodeApplyableProvider{
50 NodeAbstractProvider: a,
51 }
52 }
53
54 steps := []GraphTransformer{
55 // Create all our resources from the configuration and state
56 &ConfigTransformer{Config: config},
57
58 // Add the import steps
59 &ImportStateTransformer{Targets: b.ImportTargets},
60
61 // Add root variables
62 &RootVariableTransformer{Config: b.Config},
63
64 TransformProviders(b.Components.ResourceProviders(), concreteProvider, config),
65
66 // This validates that the providers only depend on variables
67 &ImportProviderValidateTransformer{},
68
69 // Add the local values
70 &LocalTransformer{Config: b.Config},
71
72 // Add the outputs
73 &OutputTransformer{Config: b.Config},
74
75 // Add module variables
76 &ModuleVariableTransformer{Config: b.Config},
77
78 // Must attach schemas before ReferenceTransformer so that we can
79 // analyze the configuration to find references.
80 &AttachSchemaTransformer{Schemas: b.Schemas},
81
82 // Connect so that the references are ready for targeting. We'll
83 // have to connect again later for providers and so on.
84 &ReferenceTransformer{},
85
86 // Close opened plugin connections
87 &CloseProviderTransformer{},
88
89 // Single root
90 &RootTransformer{},
91
92 // Optimize
93 &TransitiveReductionTransformer{},
94 }
95
96 return steps
97 }