-
Notifications
You must be signed in to change notification settings - Fork 54
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
Added support for #14
Conversation
llyys
commented
Sep 7, 2020
- standard functions
- negative numbers
- standard functions - negative numbers
The negative number part of this, I think is great. The standard functions part, I'm not as sure about. As I understand this, the change is actually evaluating the function during the conversion to json, which can lose some of the original information (like the dependencies on the arguments to the function). It also only works for certain functions, which, for example doesn't work for all functions supported by terraform, and I think would cause this to error instead of translating to hcl-compatible json. I'm curious what your use-case is for evaluating functions at translation time? I'd also be more ok with it if it was behind a flag. |
The problem is that terraform does not support nested maps
As these functions are part of standard TF functions I thought it's nice to have those things |
So, currently if you have something like
And terraform can handle this syntax just fine. It sounds like you want it to be encoded as:
I'm still not sure what the use case for that is. I also don't want to accept this PR as is, because if there is a function hcl2json doesn't know about, or it can't evaluate an argument to a function (for example because it uses a reference to another resource in terraform), then it will fail. I might accept it if hcl2json gracefully falls back to the current behavior if it is unable to successfully evaluate the function, especially if there is a flag to toggle the behavior. |
I added the negative number support in e4347db |
@@ -90,10 +111,15 @@ func (c *converter) convertExpression(expr hclsyntax.Expression) (interface{}, e | |||
switch value := expr.(type) { | |||
case *hclsyntax.LiteralValueExpr: | |||
return ctyjson.SimpleJSONValue{Value: value.Val}, nil | |||
case *hclsyntax.UnaryOpExpr: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is already on master.
} | ||
value, valueDiags := expr.Value(specCtx) | ||
if valueDiags.HasErrors() { | ||
return nil, fmt.Errorf(valueDiags.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fall back to the existing behavior of wrapping the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's not that important.
b59e3a3 may interest you. |