github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/config/lang/transform_fixed.go (about)

     1  package lang
     2  
     3  import (
     4  	"github.com/hashicorp/terraform/config/lang/ast"
     5  )
     6  
     7  // FixedValueTransform transforms an AST to return a fixed value for
     8  // all interpolations. i.e. you can make "hello ${anything}" always
     9  // turn into "hello foo".
    10  func FixedValueTransform(root ast.Node, Value *ast.LiteralNode) ast.Node {
    11  	// We visit the nodes in top-down order
    12  	result := root
    13  	switch n := result.(type) {
    14  	case *ast.Concat:
    15  		for i, v := range n.Exprs {
    16  			n.Exprs[i] = FixedValueTransform(v, Value)
    17  		}
    18  	case *ast.LiteralNode:
    19  		// We keep it as-is
    20  	default:
    21  		// Anything else we replace
    22  		result = Value
    23  	}
    24  
    25  	return result
    26  }