diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/hil/transform_fixed.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/hil/transform_fixed.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/transform_fixed.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hil/transform_fixed.go b/vendor/github.com/hashicorp/hil/transform_fixed.go new file mode 100644 index 0000000..e69df29 --- /dev/null +++ b/vendor/github.com/hashicorp/hil/transform_fixed.go | |||
@@ -0,0 +1,29 @@ | |||
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 | } | ||