Mainly redefine or reused what Terraform did. * allow to used `variables`, `variable` and `local` blocks * import the following functions and their docs from Terraform: abs, abspath, basename, base64decode, base64encode, bcrypt, can, ceil, chomp, chunklist, cidrhost, cidrnetmask, cidrsubnet, cidrsubnets, coalesce, coalescelist, compact, concat, contains, convert, csvdecode, dirname, distinct, element, file, fileexists, fileset, flatten, floor, format, formatdate, formatlist, indent, index, join, jsondecode, jsonencode, keys, length, log, lookup, lower, max, md5, merge, min, parseint, pathexpand, pow, range, reverse, rsadecrypt, setintersection, setproduct, setunion, sha1, sha256, sha512, signum, slice, sort, split, strrev, substr, timestamp, timeadd, title, trim, trimprefix, trimspace, trimsuffix, try, upper, urlencode, uuidv4, uuidv5, values, yamldecode, yamlencode, zipmap.
32 lines
753 B
Go
32 lines
753 B
Go
package convert
|
|
|
|
import (
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func conversionToCapsule(inTy, outTy cty.Type, fn func(inTy cty.Type) func(cty.Value, cty.Path) (interface{}, error)) conversion {
|
|
rawConv := fn(inTy)
|
|
if rawConv == nil {
|
|
return nil
|
|
}
|
|
|
|
return func(in cty.Value, path cty.Path) (cty.Value, error) {
|
|
rawV, err := rawConv(in, path)
|
|
if err != nil {
|
|
return cty.NilVal, err
|
|
}
|
|
return cty.CapsuleVal(outTy, rawV), nil
|
|
}
|
|
}
|
|
|
|
func conversionFromCapsule(inTy, outTy cty.Type, fn func(outTy cty.Type) func(interface{}, cty.Path) (cty.Value, error)) conversion {
|
|
rawConv := fn(outTy)
|
|
if rawConv == nil {
|
|
return nil
|
|
}
|
|
|
|
return func(in cty.Value, path cty.Path) (cty.Value, error) {
|
|
return rawConv(in.EncapsulatedValue(), path)
|
|
}
|
|
}
|