mercari / hcledit

Go package to edit HCL configuration
MIT License
44 stars 13 forks source link

[hcledit/read] fallback to raw values if unparsable #100

Closed ryan-ph closed 4 months ago

ryan-ph commented 4 months ago

WHAT

Currently this package always passes a nil EvalContext when evaluating HCL expressions. This means any value that references other attributes will fail to parse. This PR adds a fallback in this case to return the raw, un-evaluated value.

WHY

There's a couple reasons why this is useful:

  1. In the case where the HCL file is referencing the output of a module, we'll never be able to correctly evaluate the final value without looking at the Terraform state. In cases like this, it makes sense to return the un-evaluated value since this CLI does not read any TF state or allow a way to input substitutions for EvalContext.
  2. This module currently doesn't allow for users to programatically provide any EvalContext when executing a read operation. When working with and writing HCL files programatically, it's useful to just get the un-evaluated value as we generally are not planning on completely evaluating and replacing interpolated values / expression references with literals.