From dd6fb16971c88489d48e806c073769f8d2ff3ce9 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Mon, 2 Mar 2020 15:35:35 -0500 Subject: [PATCH 1/3] Deletions in the config package --- config/interpolate.go | 4 --- config/interpolate_funcs.go | 54 ------------------------------------- config/lang.go | 11 -------- config/raw_config.go | 11 +------- 4 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 config/interpolate_funcs.go delete mode 100644 config/lang.go diff --git a/config/interpolate.go b/config/interpolate.go index 599e5ecdb..4cc9e9757 100644 --- a/config/interpolate.go +++ b/config/interpolate.go @@ -29,10 +29,6 @@ func (r varRange) SourceRange() tfdiags.SourceRange { return r.rng } -func makeVarRange(rng tfdiags.SourceRange) varRange { - return varRange{rng} -} - // CountVariable is a variable for referencing information about // the count. type CountVariable struct { diff --git a/config/interpolate_funcs.go b/config/interpolate_funcs.go deleted file mode 100644 index 1f3f67b90..000000000 --- a/config/interpolate_funcs.go +++ /dev/null @@ -1,54 +0,0 @@ -package config - -import ( - "fmt" - - "github.com/hashicorp/hil/ast" -) - -// stringSliceToVariableValue converts a string slice into the value -// required to be returned from interpolation functions which return -// TypeList. -func stringSliceToVariableValue(values []string) []ast.Variable { - output := make([]ast.Variable, len(values)) - for index, value := range values { - output[index] = ast.Variable{ - Type: ast.TypeString, - Value: value, - } - } - return output -} - -// listVariableSliceToVariableValue converts a list of lists into the value -// required to be returned from interpolation functions which return TypeList. -func listVariableSliceToVariableValue(values [][]ast.Variable) []ast.Variable { - output := make([]ast.Variable, len(values)) - - for index, value := range values { - output[index] = ast.Variable{ - Type: ast.TypeList, - Value: value, - } - } - return output -} - -func listVariableValueToStringSlice(values []ast.Variable) ([]string, error) { - output := make([]string, len(values)) - for index, value := range values { - if value.Type != ast.TypeString { - return []string{}, fmt.Errorf("list has non-string element (%T)", value.Type.String()) - } - output[index] = value.Value.(string) - } - return output, nil -} - -// Funcs used to return a mapping of built-in functions for configuration. -// -// However, these function implementations are no longer used. To find the -// current function implementations, refer to ../lang/functions.go instead. -func Funcs() map[string]ast.Function { - return nil -} diff --git a/config/lang.go b/config/lang.go deleted file mode 100644 index 890d30beb..000000000 --- a/config/lang.go +++ /dev/null @@ -1,11 +0,0 @@ -package config - -import ( - "github.com/hashicorp/hil/ast" -) - -type noopNode struct{} - -func (n *noopNode) Accept(ast.Visitor) ast.Node { return n } -func (n *noopNode) Pos() ast.Pos { return ast.Pos{} } -func (n *noopNode) Type(ast.Scope) (ast.Type, error) { return ast.TypeString, nil } diff --git a/config/raw_config.go b/config/raw_config.go index 27bcd1da0..db99f17ac 100644 --- a/config/raw_config.go +++ b/config/raw_config.go @@ -401,19 +401,10 @@ type gobRawConfig struct { } // langEvalConfig returns the evaluation configuration we use to execute. -// -// The interpolation functions are no longer available here, because this -// codepath is no longer used. Instead, see ../lang/functions.go . func langEvalConfig(vs map[string]ast.Variable) *hil.EvalConfig { - funcMap := make(map[string]ast.Function) - for k, v := range Funcs() { - funcMap[k] = v - } - return &hil.EvalConfig{ GlobalScope: &ast.BasicScope{ - VarMap: vs, - FuncMap: funcMap, + VarMap: vs, }, } } From fa3b54c0c4c6a2a97d1ee4647350487e99bb7c90 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Mon, 2 Mar 2020 15:54:50 -0500 Subject: [PATCH 2/3] Move type construction out, delete func --- config/raw_config.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/config/raw_config.go b/config/raw_config.go index db99f17ac..677ccce2b 100644 --- a/config/raw_config.go +++ b/config/raw_config.go @@ -162,7 +162,11 @@ func (r *RawConfig) Interpolate(vs map[string]ast.Variable) error { r.lock.Lock() defer r.lock.Unlock() - config := langEvalConfig(vs) + config := &hil.EvalConfig{ + GlobalScope: &ast.BasicScope{ + VarMap: vs, + }, + } return r.interpolate(func(root ast.Node) (interface{}, error) { // None of the variables we need are computed, meaning we should // be able to properly evaluate. @@ -399,12 +403,3 @@ type gobRawConfig struct { Key string Raw map[string]interface{} } - -// langEvalConfig returns the evaluation configuration we use to execute. -func langEvalConfig(vs map[string]ast.Variable) *hil.EvalConfig { - return &hil.EvalConfig{ - GlobalScope: &ast.BasicScope{ - VarMap: vs, - }, - } -} From 1a8e7cbd1b8524690e6411f6a012359f66aefa76 Mon Sep 17 00:00:00 2001 From: Pam Selle <204372+pselle@users.noreply.github.com> Date: Mon, 2 Mar 2020 15:56:38 -0500 Subject: [PATCH 3/3] Move the commit along with --- config/raw_config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/config/raw_config.go b/config/raw_config.go index 677ccce2b..32d38114c 100644 --- a/config/raw_config.go +++ b/config/raw_config.go @@ -162,6 +162,7 @@ func (r *RawConfig) Interpolate(vs map[string]ast.Variable) error { r.lock.Lock() defer r.lock.Unlock() + // Create the evaluation configuration we use to execute config := &hil.EvalConfig{ GlobalScope: &ast.BasicScope{ VarMap: vs,