-1

I want to introduce a simple timestamp to my ec2 instance names

   tags = {

    "Name" = "windows server 2012 ${var.env} - ${formatdate("YYYYMMDD", timestamp())}"
}

However when I run terraform validate,

I got this

Error: aws_instance.convertor: 1 error(s) occurred:

* aws_instance.convertor: 1:33: unknown function called: formatdate in:

 windows server 2012 ${var.env} - ${formatdate("YYYYMMDD", timestamp())}

Apparently formatdate is not available in my version of terraform (v0.11.7). How can I achieve the same result in HCL of 0.11.7?

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304

1 Answers1

1

formatdate function is only available from terraform v0.12. What You can do is use some string manipulation to get your result as explain here (Terraform timestamp() to numbers only string) and do a simple substring, not a very elegant solution but it works.

locals {
 timestamp = "${timestamp()}"
 timestamp_sanitized = "${substr(replace("${local.timestamp}", "/[-| |T|Z|:]/", ""),0,8)}"
}

output "timestamp" {
  value = "${local.timestamp_sanitized}"
}