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

Custom expression decoding in function calls and hcldec specs #330

Merged
merged 3 commits into from
Dec 17, 2019

Commits on Dec 14, 2019

  1. go get github.com/zclconf/go-cty@v1.2.0

    This includes a new feature to allow extension properties associated with
    capsule types, which HCL can in turn use to allow certain capsule types
    to opt in to special handing at the HCL layer.
    
    (There are no such hooks in use as of this commit, however.)
    apparentlymart committed Dec 14, 2019
    Configuration menu
    Copy the full SHA
    893c8a3 View commit details
    Browse the repository at this point in the history
  2. ext/customdecode: Custom expression decoding extension

    Most of the time, the standard expression decoding built in to HCL is
    sufficient. Sometimes though, it's useful to be able to customize the
    decoding of certain arguments where the application intends to use them
    in a very specific way, such as in static analysis.
    
    This extension is an approximate analog of gohcl's support for decoding
    into an hcl.Expression, allowing hcldec-based applications and
    applications with custom functions to similarly capture and manipulate
    the physical expressions used in arguments, rather than their values.
    
    This includes one example use-case: the typeexpr extension now includes
    a cty.Function called ConvertFunc that takes a type expression as its
    second argument. A type expression is not evaluatable in the usual sense,
    but thanks to cty capsule types we _can_ produce a cty.Value from one
    and then make use of it inside the function implementation, without
    exposing this custom type to the broader language:
    
        convert(["foo"], set(string))
    
    This mechanism is intentionally restricted only to "argument-like"
    locations where there is a specific type we are attempting to decode into.
    For now, that's hcldec AttrSpec/BlockAttrsSpec -- analogous to gohcl
    decoding into hcl.Expression -- and in arguments to functions.
    apparentlymart committed Dec 14, 2019
    Configuration menu
    Copy the full SHA
    27d079d View commit details
    Browse the repository at this point in the history
  3. ext/tryfunc: Extension functions for error handling

    The try(...) and can(...) functions are intended to make it more
    convenient to work with deep data structures of unknown shape, by allowing
    a caller to concisely try a complex traversal operation against a value
    without having to guard against each possible failure mode individually.
    
    These rely on the customdecode extension to get access to their argument
    expressions directly, rather than only the results of evaluating those
    expressions. The expressions can then be evaluated in a controlled manner
    so that any resulting errors can be recognized and suppressed as
    appropriate.
    apparentlymart committed Dec 14, 2019
    Configuration menu
    Copy the full SHA
    c62f150 View commit details
    Browse the repository at this point in the history