terraform-linters / tflint-plugin-sdk

Experimental: TFLint plugin SDK for building custom rules
Mozilla Public License 2.0
18 stars 14 forks source link

`runner.EvaluateExpr` alternative that returns cty value #315

Closed matt-FFFFFF closed 3 months ago

matt-FFFFFF commented 3 months ago

Introduction

We have a scenario where we need to check if a resource attribute value is unknown.

The current runner.EvaluateExpr method needs a go type, which makes this difficult to ascertain as the conversion from cty to go types loses this information.

Proposal

An additional method for the tflint.Runner interface that allows expression evaluation but returns a cty.Value.

The caller can then make its own assertions on this value.

Alternatively

A way to return a fully populated hcl.EvalContext from the runner for use in (hcl.Expression) Value()

References

wata727 commented 3 months ago

You can use EvaluateExpr with cty.Value instead of converting the given value to a Go primitive type as follows:

err := runner.EvaluateExpr(expr, func (val cty.Value), error {
  // Test values
}, nil)
matt-FFFFFF commented 3 months ago

I did not know that - many thanks