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
This answer just shows an example of @BMW's answer which wasn't obvious to someone that's new to Terraform.
$ cat main.tf
locals {
timestamp = "${timestamp()}"
timestamp_sanitized = "${replace("${local.timestamp}", "/[-| |T|Z|:]/", "")}"
}
output "timestamp" {
value = "${local.timestamp_sanitized}"
}
Run #1:
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
timestamp = 20190221205825
Run #2:
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
timestamp = 20190221205839