github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/eval_context.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/hcl/v2"
     5  	"github.com/hashicorp/terraform-plugin-sdk/internal/addrs"
     6  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema"
     7  	"github.com/hashicorp/terraform-plugin-sdk/internal/lang"
     8  	"github.com/hashicorp/terraform-plugin-sdk/internal/plans"
     9  	"github.com/hashicorp/terraform-plugin-sdk/internal/providers"
    10  	"github.com/hashicorp/terraform-plugin-sdk/internal/provisioners"
    11  	"github.com/hashicorp/terraform-plugin-sdk/internal/states"
    12  	"github.com/hashicorp/terraform-plugin-sdk/internal/tfdiags"
    13  	"github.com/zclconf/go-cty/cty"
    14  )
    15  
    16  // EvalContext is the interface that is given to eval nodes to execute.
    17  type EvalContext interface {
    18  	// Stopped returns a channel that is closed when evaluation is stopped
    19  	// via Terraform.Context.Stop()
    20  	Stopped() <-chan struct{}
    21  
    22  	// Path is the current module path.
    23  	Path() addrs.ModuleInstance
    24  
    25  	// Hook is used to call hook methods. The callback is called for each
    26  	// hook and should return the hook action to take and the error.
    27  	Hook(func(Hook) (HookAction, error)) error
    28  
    29  	// Input is the UIInput object for interacting with the UI.
    30  	Input() UIInput
    31  
    32  	// InitProvider initializes the provider with the given type and address, and
    33  	// returns the implementation of the resource provider or an error.
    34  	//
    35  	// It is an error to initialize the same provider more than once.
    36  	InitProvider(typ string, addr addrs.ProviderConfig) (providers.Interface, error)
    37  
    38  	// Provider gets the provider instance with the given address (already
    39  	// initialized) or returns nil if the provider isn't initialized.
    40  	//
    41  	// This method expects an _absolute_ provider configuration address, since
    42  	// resources in one module are able to use providers from other modules.
    43  	// InitProvider must've been called on the EvalContext of the module
    44  	// that owns the given provider before calling this method.
    45  	Provider(addrs.AbsProviderConfig) providers.Interface
    46  
    47  	// ProviderSchema retrieves the schema for a particular provider, which
    48  	// must have already been initialized with InitProvider.
    49  	//
    50  	// This method expects an _absolute_ provider configuration address, since
    51  	// resources in one module are able to use providers from other modules.
    52  	ProviderSchema(addrs.AbsProviderConfig) *ProviderSchema
    53  
    54  	// CloseProvider closes provider connections that aren't needed anymore.
    55  	CloseProvider(addrs.ProviderConfig) error
    56  
    57  	// ConfigureProvider configures the provider with the given
    58  	// configuration. This is a separate context call because this call
    59  	// is used to store the provider configuration for inheritance lookups
    60  	// with ParentProviderConfig().
    61  	ConfigureProvider(addrs.ProviderConfig, cty.Value) tfdiags.Diagnostics
    62  
    63  	// ProviderInput and SetProviderInput are used to configure providers
    64  	// from user input.
    65  	ProviderInput(addrs.ProviderConfig) map[string]cty.Value
    66  	SetProviderInput(addrs.ProviderConfig, map[string]cty.Value)
    67  
    68  	// InitProvisioner initializes the provisioner with the given name and
    69  	// returns the implementation of the resource provisioner or an error.
    70  	//
    71  	// It is an error to initialize the same provisioner more than once.
    72  	InitProvisioner(string) (provisioners.Interface, error)
    73  
    74  	// Provisioner gets the provisioner instance with the given name (already
    75  	// initialized) or returns nil if the provisioner isn't initialized.
    76  	Provisioner(string) provisioners.Interface
    77  
    78  	// ProvisionerSchema retrieves the main configuration schema for a
    79  	// particular provisioner, which must have already been initialized with
    80  	// InitProvisioner.
    81  	ProvisionerSchema(string) *configschema.Block
    82  
    83  	// CloseProvisioner closes provisioner connections that aren't needed
    84  	// anymore.
    85  	CloseProvisioner(string) error
    86  
    87  	// EvaluateBlock takes the given raw configuration block and associated
    88  	// schema and evaluates it to produce a value of an object type that
    89  	// conforms to the implied type of the schema.
    90  	//
    91  	// The "self" argument is optional. If given, it is the referenceable
    92  	// address that the name "self" should behave as an alias for when
    93  	// evaluating. Set this to nil if the "self" object should not be available.
    94  	//
    95  	// The "key" argument is also optional. If given, it is the instance key
    96  	// of the current object within the multi-instance container it belongs
    97  	// to. For example, on a resource block with "count" set this should be
    98  	// set to a different addrs.IntKey for each instance created from that
    99  	// block. Set this to addrs.NoKey if not appropriate.
   100  	//
   101  	// The returned body is an expanded version of the given body, with any
   102  	// "dynamic" blocks replaced with zero or more static blocks. This can be
   103  	// used to extract correct source location information about attributes of
   104  	// the returned object value.
   105  	EvaluateBlock(body hcl.Body, schema *configschema.Block, self addrs.Referenceable, keyData InstanceKeyEvalData) (cty.Value, hcl.Body, tfdiags.Diagnostics)
   106  
   107  	// EvaluateExpr takes the given HCL expression and evaluates it to produce
   108  	// a value.
   109  	//
   110  	// The "self" argument is optional. If given, it is the referenceable
   111  	// address that the name "self" should behave as an alias for when
   112  	// evaluating. Set this to nil if the "self" object should not be available.
   113  	EvaluateExpr(expr hcl.Expression, wantType cty.Type, self addrs.Referenceable) (cty.Value, tfdiags.Diagnostics)
   114  
   115  	// EvaluationScope returns a scope that can be used to evaluate reference
   116  	// addresses in this context.
   117  	EvaluationScope(self addrs.Referenceable, keyData InstanceKeyEvalData) *lang.Scope
   118  
   119  	// SetModuleCallArguments defines values for the variables of a particular
   120  	// child module call.
   121  	//
   122  	// Calling this function multiple times has merging behavior, keeping any
   123  	// previously-set keys that are not present in the new map.
   124  	SetModuleCallArguments(addrs.ModuleCallInstance, map[string]cty.Value)
   125  
   126  	// Changes returns the writer object that can be used to write new proposed
   127  	// changes into the global changes set.
   128  	Changes() *plans.ChangesSync
   129  
   130  	// State returns a wrapper object that provides safe concurrent access to
   131  	// the global state.
   132  	State() *states.SyncState
   133  }