]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hil/transform_fixed.go
Initial transfer of provider code
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hil / transform_fixed.go
1 package hil
2
3 import (
4 "github.com/hashicorp/hil/ast"
5 )
6
7 // FixedValueTransform transforms an AST to return a fixed value for
8 // all interpolations. i.e. you can make "hi ${anything}" always
9 // turn into "hi foo".
10 //
11 // The primary use case for this is for config validations where you can
12 // verify that interpolations result in a certain type of string.
13 func FixedValueTransform(root ast.Node, Value *ast.LiteralNode) ast.Node {
14 // We visit the nodes in top-down order
15 result := root
16 switch n := result.(type) {
17 case *ast.Output:
18 for i, v := range n.Exprs {
19 n.Exprs[i] = FixedValueTransform(v, Value)
20 }
21 case *ast.LiteralNode:
22 // We keep it as-is
23 default:
24 // Anything else we replace
25 result = Value
26 }
27
28 return result
29 }