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

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/hcl/v2"
     5  	"github.com/muratcelep/terraform/not-internal/addrs"
     6  	"github.com/muratcelep/terraform/not-internal/configs/configschema"
     7  	"github.com/muratcelep/terraform/not-internal/instances"
     8  	"github.com/muratcelep/terraform/not-internal/lang"
     9  	"github.com/muratcelep/terraform/not-internal/plans"
    10  	"github.com/muratcelep/terraform/not-internal/providers"
    11  	"github.com/muratcelep/terraform/not-internal/provisioners"
    12  	"github.com/muratcelep/terraform/not-internal/refactoring"
    13  	"github.com/muratcelep/terraform/not-internal/states"
    14  	"github.com/muratcelep/terraform/not-internal/tfdiags"
    15  	"github.com/zclconf/go-cty/cty"
    16  )
    17  
    18  // EvalContext is the interface that is given to eval nodes to execute.
    19  type EvalContext interface {
    20  	// Stopped returns a channel that is closed when evaluation is stopped
    21  	// via Terraform.Context.Stop()
    22  	Stopped() <-chan struct{}
    23  
    24  	// Path is the current module path.
    25  	Path() addrs.ModuleInstance
    26  
    27  	// Hook is used to call hook methods. The callback is called for each
    28  	// hook and should return the hook action to take and the error.
    29  	Hook(func(Hook) (HookAction, error)) error
    30  
    31  	// Input is the UIInput object for interacting with the UI.
    32  	Input() UIInput
    33  
    34  	// InitProvider initializes the provider with the given address, and returns
    35  	// the implementation of the resource provider or an error.
    36  	//
    37  	// It is an error to initialize the same provider more than once. This
    38  	// method will panic if the module instance address of the given provider
    39  	// configuration does not match the Path() of the EvalContext.
    40  	InitProvider(addr addrs.AbsProviderConfig) (providers.Interface, error)
    41  
    42  	// Provider gets the provider instance with the given address (already
    43  	// initialized) or returns nil if the provider isn't initialized.
    44  	//
    45  	// This method expects an _absolute_ provider configuration address, since
    46  	// resources in one module are able to use providers from other modules.
    47  	// InitProvider must've been called on the EvalContext of the module
    48  	// that owns the given provider before calling this method.
    49  	Provider(addrs.AbsProviderConfig) providers.Interface
    50  
    51  	// ProviderSchema retrieves the schema for a particular provider, which
    52  	// must have already been initialized with InitProvider.
    53  	//
    54  	// This method expects an _absolute_ provider configuration address, since
    55  	// resources in one module are able to use providers from other modules.
    56  	ProviderSchema(addrs.AbsProviderConfig) (*ProviderSchema, error)
    57  
    58  	// CloseProvider closes provider connections that aren't needed anymore.
    59  	//
    60  	// This method will panic if the module instance address of the given
    61  	// provider configuration does not match the Path() of the EvalContext.
    62  	CloseProvider(addrs.AbsProviderConfig) error
    63  
    64  	// ConfigureProvider configures the provider with the given
    65  	// configuration. This is a separate context call because this call
    66  	// is used to store the provider configuration for inheritance lookups
    67  	// with ParentProviderConfig().
    68  	//
    69  	// This method will panic if the module instance address of the given
    70  	// provider configuration does not match the Path() of the EvalContext.
    71  	ConfigureProvider(addrs.AbsProviderConfig, cty.Value) tfdiags.Diagnostics
    72  
    73  	// ProviderInput and SetProviderInput are used to configure providers
    74  	// from user input.
    75  	//
    76  	// These methods will panic if the module instance address of the given
    77  	// provider configuration does not match the Path() of the EvalContext.
    78  	ProviderInput(addrs.AbsProviderConfig) map[string]cty.Value
    79  	SetProviderInput(addrs.AbsProviderConfig, map[string]cty.Value)
    80  
    81  	// Provisioner gets the provisioner instance with the given name.
    82  	Provisioner(string) (provisioners.Interface, error)
    83  
    84  	// ProvisionerSchema retrieves the main configuration schema for a
    85  	// particular provisioner, which must have already been initialized with
    86  	// InitProvisioner.
    87  	ProvisionerSchema(string) (*configschema.Block, error)
    88  
    89  	// CloseProvisioner closes all provisioner plugins.
    90  	CloseProvisioners() error
    91  
    92  	// EvaluateBlock takes the given raw configuration block and associated
    93  	// schema and evaluates it to produce a value of an object type that
    94  	// conforms to the implied type of the schema.
    95  	//
    96  	// The "self" argument is optional. If given, it is the referenceable
    97  	// address that the name "self" should behave as an alias for when
    98  	// evaluating. Set this to nil if the "self" object should not be available.
    99  	//
   100  	// The "key" argument is also optional. If given, it is the instance key
   101  	// of the current object within the multi-instance container it belongs
   102  	// to. For example, on a resource block with "count" set this should be
   103  	// set to a different addrs.IntKey for each instance created from that
   104  	// block. Set this to addrs.NoKey if not appropriate.
   105  	//
   106  	// The returned body is an expanded version of the given body, with any
   107  	// "dynamic" blocks replaced with zero or more static blocks. This can be
   108  	// used to extract correct source location information about attributes of
   109  	// the returned object value.
   110  	EvaluateBlock(body hcl.Body, schema *configschema.Block, self addrs.Referenceable, keyData InstanceKeyEvalData) (cty.Value, hcl.Body, tfdiags.Diagnostics)
   111  
   112  	// EvaluateExpr takes the given HCL expression and evaluates it to produce
   113  	// a value.
   114  	//
   115  	// The "self" argument is optional. If given, it is the referenceable
   116  	// address that the name "self" should behave as an alias for when
   117  	// evaluating. Set this to nil if the "self" object should not be available.
   118  	EvaluateExpr(expr hcl.Expression, wantType cty.Type, self addrs.Referenceable) (cty.Value, tfdiags.Diagnostics)
   119  
   120  	// EvaluationScope returns a scope that can be used to evaluate reference
   121  	// addresses in this context.
   122  	EvaluationScope(self addrs.Referenceable, keyData InstanceKeyEvalData) *lang.Scope
   123  
   124  	// SetModuleCallArguments defines values for the variables of a particular
   125  	// child module call.
   126  	//
   127  	// Calling this function multiple times has merging behavior, keeping any
   128  	// previously-set keys that are not present in the new map.
   129  	SetModuleCallArguments(addrs.ModuleCallInstance, map[string]cty.Value)
   130  
   131  	// GetVariableValue returns the value provided for the input variable with
   132  	// the given address, or cty.DynamicVal if the variable hasn't been assigned
   133  	// a value yet.
   134  	//
   135  	// Most callers should deal with variable values only indirectly via
   136  	// EvaluationScope and the other expression evaluation functions, but
   137  	// this is provided because variables tend to be evaluated outside of
   138  	// the context of the module they belong to and so we sometimes need to
   139  	// override the normal expression evaluation behavior.
   140  	GetVariableValue(addr addrs.AbsInputVariableInstance) cty.Value
   141  
   142  	// Changes returns the writer object that can be used to write new proposed
   143  	// changes into the global changes set.
   144  	Changes() *plans.ChangesSync
   145  
   146  	// State returns a wrapper object that provides safe concurrent access to
   147  	// the global state.
   148  	State() *states.SyncState
   149  
   150  	// RefreshState returns a wrapper object that provides safe concurrent
   151  	// access to the state used to store the most recently refreshed resource
   152  	// values.
   153  	RefreshState() *states.SyncState
   154  
   155  	// PrevRunState returns a wrapper object that provides safe concurrent
   156  	// access to the state which represents the result of the previous run,
   157  	// updated only so that object data conforms to current schemas for
   158  	// meaningful comparison with RefreshState.
   159  	PrevRunState() *states.SyncState
   160  
   161  	// InstanceExpander returns a helper object for tracking the expansion of
   162  	// graph nodes during the plan phase in response to "count" and "for_each"
   163  	// arguments.
   164  	//
   165  	// The InstanceExpander is a global object that is shared across all of the
   166  	// EvalContext objects for a given configuration.
   167  	InstanceExpander() *instances.Expander
   168  
   169  	// MoveResults returns a map describing the results of handling any
   170  	// resource instance move statements prior to the graph walk, so that
   171  	// the graph walk can then record that information appropriately in other
   172  	// artifacts produced by the graph walk.
   173  	//
   174  	// This data structure is created prior to the graph walk and read-only
   175  	// thereafter, so callers must not modify the returned map or any other
   176  	// objects accessible through it.
   177  	MoveResults() refactoring.MoveResults
   178  
   179  	// WithPath returns a copy of the context with the not-internal path set to the
   180  	// path argument.
   181  	WithPath(path addrs.ModuleInstance) EvalContext
   182  }