github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/not-internal/terraform/graph_builder_eval.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/muratcelep/terraform/not-internal/addrs"
     5  	"github.com/muratcelep/terraform/not-internal/configs"
     6  	"github.com/muratcelep/terraform/not-internal/dag"
     7  	"github.com/muratcelep/terraform/not-internal/states"
     8  	"github.com/muratcelep/terraform/not-internal/tfdiags"
     9  )
    10  
    11  // EvalGraphBuilder implements GraphBuilder and constructs a graph suitable
    12  // for evaluating in-memory values (input variables, local values, output
    13  // values) in the state without any other side-effects.
    14  //
    15  // This graph is used only in weird cases, such as the "terraform console"
    16  // CLI command, where we need to evaluate expressions against the state
    17  // without taking any other actions.
    18  //
    19  // The generated graph will include nodes for providers, resources, etc
    20  // just to allow indirect dependencies to be resolved, but these nodes will
    21  // not take any actions themselves since we assume that their parts of the
    22  // state, if any, are already complete.
    23  //
    24  // Although the providers are never configured, they must still be available
    25  // in order to obtain schema information used for type checking, etc.
    26  type EvalGraphBuilder struct {
    27  	// Config is the configuration tree.
    28  	Config *configs.Config
    29  
    30  	// State is the current state
    31  	State *states.State
    32  
    33  	// Plugins is a library of plug-in components (providers and
    34  	// provisioners) available for use.
    35  	Plugins *contextPlugins
    36  }
    37  
    38  // See GraphBuilder
    39  func (b *EvalGraphBuilder) Build(path addrs.ModuleInstance) (*Graph, tfdiags.Diagnostics) {
    40  	return (&BasicGraphBuilder{
    41  		Steps:    b.Steps(),
    42  		Validate: true,
    43  		Name:     "EvalGraphBuilder",
    44  	}).Build(path)
    45  }
    46  
    47  // See GraphBuilder
    48  func (b *EvalGraphBuilder) Steps() []GraphTransformer {
    49  	concreteProvider := func(a *NodeAbstractProvider) dag.Vertex {
    50  		return &NodeEvalableProvider{
    51  			NodeAbstractProvider: a,
    52  		}
    53  	}
    54  
    55  	steps := []GraphTransformer{
    56  		// Creates all the data resources that aren't in the state. This will also
    57  		// add any orphans from scaling in as destroy nodes.
    58  		&ConfigTransformer{
    59  			Config: b.Config,
    60  		},
    61  
    62  		// Add dynamic values
    63  		&RootVariableTransformer{Config: b.Config},
    64  		&ModuleVariableTransformer{Config: b.Config},
    65  		&LocalTransformer{Config: b.Config},
    66  		&OutputTransformer{Config: b.Config},
    67  
    68  		// Attach the configuration to any resources
    69  		&AttachResourceConfigTransformer{Config: b.Config},
    70  
    71  		// Attach the state
    72  		&AttachStateTransformer{State: b.State},
    73  
    74  		transformProviders(concreteProvider, b.Config),
    75  
    76  		// Must attach schemas before ReferenceTransformer so that we can
    77  		// analyze the configuration to find references.
    78  		&AttachSchemaTransformer{Plugins: b.Plugins, Config: b.Config},
    79  
    80  		// Create expansion nodes for all of the module calls. This must
    81  		// come after all other transformers that create nodes representing
    82  		// objects that can belong to modules.
    83  		&ModuleExpansionTransformer{Config: b.Config},
    84  
    85  		// Connect so that the references are ready for targeting. We'll
    86  		// have to connect again later for providers and so on.
    87  		&ReferenceTransformer{},
    88  
    89  		// Although we don't configure providers, we do still start them up
    90  		// to get their schemas, and so we must shut them down again here.
    91  		&CloseProviderTransformer{},
    92  
    93  		// Close root module
    94  		&CloseRootModuleTransformer{},
    95  
    96  		// Remove redundant edges to simplify the graph.
    97  		&TransitiveReductionTransformer{},
    98  	}
    99  
   100  	return steps
   101  }