The timestamp() function in the interpolation syntax will return an ISO 8601 formatted string, which looks like this 2019-02-06T23:22:28Z
. However, I want to have a
The current interpolate function timestamp() has been hardcoded with output format RFC3339
in the source code:
https://github.com/hashicorp/terraform/blob/master/config/interpolate_funcs.go#L1521
return time.Now().UTC().Format(time.RFC3339), nil
So there is nothing wrong with your way, however we can improve it a little bit.
locals {
timestamp = "${timestamp()}"
timestamp_sanitized = "${replace("${local.timestamp}", "/[- TZ:]/", "")}"
}
Reference:
https://github.com/google/re2/wiki/Syntax
replace(string, search, replace) - Does a search and replace on the given string. All instances of search are replaced with the value of replace. If search is wrapped in forward slashes, it is treated as a regular expression. If using a regular expression, replace can reference subcaptures in the regular expression by using $n where n is the index or name of the subcapture. If using a regular expression, the syntax conforms to the re2 regular expression syntax.