github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/config/interpolate_funcs.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/hil/ast"
     7  )
     8  
     9  // stringSliceToVariableValue converts a string slice into the value
    10  // required to be returned from interpolation functions which return
    11  // TypeList.
    12  func stringSliceToVariableValue(values []string) []ast.Variable {
    13  	output := make([]ast.Variable, len(values))
    14  	for index, value := range values {
    15  		output[index] = ast.Variable{
    16  			Type:  ast.TypeString,
    17  			Value: value,
    18  		}
    19  	}
    20  	return output
    21  }
    22  
    23  // listVariableSliceToVariableValue converts a list of lists into the value
    24  // required to be returned from interpolation functions which return TypeList.
    25  func listVariableSliceToVariableValue(values [][]ast.Variable) []ast.Variable {
    26  	output := make([]ast.Variable, len(values))
    27  
    28  	for index, value := range values {
    29  		output[index] = ast.Variable{
    30  			Type:  ast.TypeList,
    31  			Value: value,
    32  		}
    33  	}
    34  	return output
    35  }
    36  
    37  func listVariableValueToStringSlice(values []ast.Variable) ([]string, error) {
    38  	output := make([]string, len(values))
    39  	for index, value := range values {
    40  		if value.Type != ast.TypeString {
    41  			return []string{}, fmt.Errorf("list has non-string element (%T)", value.Type.String())
    42  		}
    43  		output[index] = value.Value.(string)
    44  	}
    45  	return output, nil
    46  }
    47  
    48  // Funcs used to return a mapping of built-in functions for configuration.
    49  //
    50  // However, these function implementations are no longer used. To find the
    51  // current function implementations, refer to ../lang/functions.go  instead.
    52  func Funcs() map[string]ast.Function {
    53  	return nil
    54  }