diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/eval_filter_operation.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/eval_filter_operation.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/eval_filter_operation.go b/vendor/github.com/hashicorp/terraform/terraform/eval_filter_operation.go new file mode 100644 index 0000000..1a55f02 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/terraform/eval_filter_operation.go | |||
@@ -0,0 +1,49 @@ | |||
1 | package terraform | ||
2 | |||
3 | // EvalNodeOpFilterable is an interface that EvalNodes can implement | ||
4 | // to be filterable by the operation that is being run on Terraform. | ||
5 | type EvalNodeOpFilterable interface { | ||
6 | IncludeInOp(walkOperation) bool | ||
7 | } | ||
8 | |||
9 | // EvalNodeFilterOp returns a filter function that filters nodes that | ||
10 | // include themselves in specific operations. | ||
11 | func EvalNodeFilterOp(op walkOperation) EvalNodeFilterFunc { | ||
12 | return func(n EvalNode) EvalNode { | ||
13 | include := true | ||
14 | if of, ok := n.(EvalNodeOpFilterable); ok { | ||
15 | include = of.IncludeInOp(op) | ||
16 | } | ||
17 | if include { | ||
18 | return n | ||
19 | } | ||
20 | |||
21 | return EvalNoop{} | ||
22 | } | ||
23 | } | ||
24 | |||
25 | // EvalOpFilter is an EvalNode implementation that is a proxy to | ||
26 | // another node but filters based on the operation. | ||
27 | type EvalOpFilter struct { | ||
28 | // Ops is the list of operations to include this node in. | ||
29 | Ops []walkOperation | ||
30 | |||
31 | // Node is the node to execute | ||
32 | Node EvalNode | ||
33 | } | ||
34 | |||
35 | // TODO: test | ||
36 | func (n *EvalOpFilter) Eval(ctx EvalContext) (interface{}, error) { | ||
37 | return EvalRaw(n.Node, ctx) | ||
38 | } | ||
39 | |||
40 | // EvalNodeOpFilterable impl. | ||
41 | func (n *EvalOpFilter) IncludeInOp(op walkOperation) bool { | ||
42 | for _, v := range n.Ops { | ||
43 | if v == op { | ||
44 | return true | ||
45 | } | ||
46 | } | ||
47 | |||
48 | return false | ||
49 | } | ||