github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/internal/lang/scope.go (about) 1 package lang 2 3 import ( 4 "sync" 5 6 "github.com/zclconf/go-cty/cty/function" 7 8 "github.com/iaas-resource-provision/iaas-rpc/internal/addrs" 9 "github.com/iaas-resource-provision/iaas-rpc/internal/experiments" 10 ) 11 12 // Scope is the main type in this package, allowing dynamic evaluation of 13 // blocks and expressions based on some contextual information that informs 14 // which variables and functions will be available. 15 type Scope struct { 16 // Data is used to resolve references in expressions. 17 Data Data 18 19 // SelfAddr is the address that the "self" object should be an alias of, 20 // or nil if the "self" object should not be available at all. 21 SelfAddr addrs.Referenceable 22 23 // BaseDir is the base directory used by any interpolation functions that 24 // accept filesystem paths as arguments. 25 BaseDir string 26 27 // PureOnly can be set to true to request that any non-pure functions 28 // produce unknown value results rather than actually executing. This is 29 // important during a plan phase to avoid generating results that could 30 // then differ during apply. 31 PureOnly bool 32 33 funcs map[string]function.Function 34 funcsLock sync.Mutex 35 36 // activeExperiments is an optional set of experiments that should be 37 // considered as active in the module that this scope will be used for. 38 // Callers can populate it by calling the SetActiveExperiments method. 39 activeExperiments experiments.Set 40 } 41 42 // SetActiveExperiments allows a caller to declare that a set of experiments 43 // is active for the module that the receiving Scope belongs to, which might 44 // then cause the scope to activate some additional experimental behaviors. 45 func (s *Scope) SetActiveExperiments(active experiments.Set) { 46 s.activeExperiments = active 47 }