mirror of
https://github.com/mcuadros/ascode
synced 2024-11-22 17:02:03 +01:00
starlark/types: evaluate include main thread predeclared variables
This commit is contained in:
parent
1643ed115e
commit
bac0f66196
@ -51,6 +51,16 @@ type Runtime struct {
|
||||
// NewRuntime returns a new Runtime for the given terraform.PluginManager.
|
||||
func NewRuntime(pm *terraform.PluginManager) *Runtime {
|
||||
tf := types.NewTerraform(pm)
|
||||
predeclared := starlark.StringDict{}
|
||||
predeclared["tf"] = tf
|
||||
predeclared["provisioner"] = types.BuiltinProvisioner()
|
||||
predeclared["backend"] = types.BuiltinBackend()
|
||||
predeclared["validate"] = types.BuiltinValidate()
|
||||
predeclared["hcl"] = types.BuiltinHCL()
|
||||
predeclared["fn"] = types.BuiltinFunctionAttribute()
|
||||
predeclared["evaluate"] = types.BuiltinEvaluate(predeclared)
|
||||
predeclared["struct"] = starlark.NewBuiltin("struct", starlarkstruct.Make)
|
||||
predeclared["module"] = starlark.NewBuiltin("module", starlarkstruct.MakeModule)
|
||||
|
||||
return &Runtime{
|
||||
Terraform: tf,
|
||||
@ -70,16 +80,7 @@ func NewRuntime(pm *terraform.PluginManager) *Runtime {
|
||||
"time": time.LoadModule,
|
||||
"http": http.LoadModule,
|
||||
},
|
||||
predeclared: starlark.StringDict{
|
||||
"tf": tf,
|
||||
"provisioner": types.BuiltinProvisioner(),
|
||||
"backend": types.BuiltinBackend(),
|
||||
"hcl": types.BuiltinHCL(),
|
||||
"fn": types.BuiltinFunctionAttribute(),
|
||||
"evaluate": types.BuiltinEvaluate(),
|
||||
"struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
|
||||
"module": starlark.NewBuiltin("module", starlarkstruct.MakeModule),
|
||||
},
|
||||
predeclared: predeclared,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,9 @@ import (
|
||||
// Defines the predeclared context for the execution. Execution does
|
||||
// not modify this dictionary
|
||||
//
|
||||
func BuiltinEvaluate() starlark.Value {
|
||||
func BuiltinEvaluate(predeclared starlark.StringDict) starlark.Value {
|
||||
return starlark.NewBuiltin("evaluate", func(t *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||
var raw starlark.String
|
||||
predeclared := starlark.StringDict{}
|
||||
|
||||
switch len(args) {
|
||||
case 2:
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/mcuadros/ascode/terraform"
|
||||
"go.starlark.net/resolve"
|
||||
"go.starlark.net/starlark"
|
||||
"go.starlark.net/starlarkstruct"
|
||||
)
|
||||
|
||||
var id int
|
||||
@ -75,15 +76,16 @@ func doTestPrint(t *testing.T, filename string, print func(*starlark.Thread, str
|
||||
|
||||
test.SetReporter(thread, t)
|
||||
|
||||
predeclared := starlark.StringDict{
|
||||
"provisioner": BuiltinProvisioner(),
|
||||
"backend": BuiltinBackend(),
|
||||
"hcl": BuiltinHCL(),
|
||||
"fn": BuiltinFunctionAttribute(),
|
||||
"evaluate": BuiltinEvaluate(),
|
||||
"validate": BuiltinValidate(),
|
||||
"tf": NewTerraform(pm),
|
||||
}
|
||||
predeclared := starlark.StringDict{}
|
||||
predeclared["tf"] = NewTerraform(pm)
|
||||
predeclared["provisioner"] = BuiltinProvisioner()
|
||||
predeclared["backend"] = BuiltinBackend()
|
||||
predeclared["hcl"] = BuiltinHCL()
|
||||
predeclared["validate"] = BuiltinValidate()
|
||||
predeclared["fn"] = BuiltinFunctionAttribute()
|
||||
predeclared["evaluate"] = BuiltinEvaluate(predeclared)
|
||||
predeclared["struct"] = starlark.NewBuiltin("struct", starlarkstruct.Make)
|
||||
predeclared["module"] = starlark.NewBuiltin("module", starlarkstruct.MakeModule)
|
||||
|
||||
_, err := starlark.ExecFile(thread, filename, nil, predeclared)
|
||||
if err != nil {
|
||||
|
3
starlark/types/testdata/evaluate/test.star
vendored
3
starlark/types/testdata/evaluate/test.star
vendored
@ -1 +1,2 @@
|
||||
foo = bar
|
||||
foo = bar
|
||||
tf
|
Loading…
Reference in New Issue
Block a user