Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 24, 2024

Conversation

ryan-ph
Copy link
Member

@ryan-ph ryan-ph commented Apr 22, 2024

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.

@ryan-ph ryan-ph force-pushed the ryan-ph/read/default-raw-expression branch from c116cb5 to 209d0da Compare April 22, 2024 05:52
@ryan-ph ryan-ph force-pushed the ryan-ph/read/default-raw-expression branch from 209d0da to 54256f8 Compare April 22, 2024 09:01
@@ -30,3 +31,9 @@ func WithNewLine() Option {
opt.beforeNewline = true
}
}

func WithReadFallbackToRawString() Option {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree with the code comment left above that we should probably split these into operation specific options, but I think that's out of scope for this PR.

@ryan-ph ryan-ph merged commit f186c5c into mercari:main Apr 24, 2024
3 checks passed
@ryan-ph ryan-ph deleted the ryan-ph/read/default-raw-expression branch April 24, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants