193dad46e6
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.
27 lines
833 B
Go
27 lines
833 B
Go
package function
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
"github.com/zclconf/go-cty/cty/function"
|
|
)
|
|
|
|
// TimestampFunc constructs a function that returns a string representation of the current date and time.
|
|
var TimestampFunc = function.New(&function.Spec{
|
|
Params: []function.Parameter{},
|
|
Type: function.StaticReturnType(cty.String),
|
|
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
|
|
return cty.StringVal(time.Now().UTC().Format(time.RFC3339)), nil
|
|
},
|
|
})
|
|
|
|
// Timestamp returns a string representation of the current date and time.
|
|
//
|
|
// In the HCL language, timestamps are conventionally represented as strings
|
|
// using RFC 3339 "Date and Time format" syntax, and so timestamp returns a
|
|
// string in this format.
|
|
func Timestamp() (cty.Value, error) {
|
|
return TimestampFunc.Call([]cty.Value{})
|
|
}
|