This is part of an ongoing series of posts documenting the built-in interpolation functions in Terraform. For more information, check out the beginning post. In this post I am going to cover the timestamp() function. The example file is on GitHub here.
Function name: timestamp()
Returns: Takes no arguments. Returns the current time in UTC using the RFC 3339 standard.
Example:
# Returns something like 2018-09-05T00:00:00Z
output "timestamp_output" {
value = "${timestamp()}"
}
##############################################
# Function: timestamp
##############################################
##############################################
# Variables
##############################################
##############################################
# Resources
##############################################
##############################################
# Outputs
##############################################
output "1_timestamp_basic" {
value = "${timestamp()}"
}
Run the following from the timestamp folder to get example output for a number of different cases:
#No arguments for function
terraform apply
What time is it? 4:30, it’s not late, nah, it’s just early. The Spin Doctors really said it best. Seriously though, grabbing the current time is great for logging, file naming, and a host of other things. This function also works hand-in-hand with the timeadd function to get the date in the future or the past.
Not gonna lie. There wasn’t much to learn. The most important bits of this function are what is in the official documentation. Every time you run terraform apply, the value is going to change. So if a portion of the resources is using that value, then Terraform will see it as a change. It may be necessary to add ignore_changes as a lifecycle property to avoid the diff.
Coming up next is the timeadd() function.
What's New in the AzureRM Provider Version 4?
August 27, 2024
Debugging the AzureRM Provider with VSCode
August 20, 2024
State Encryption with OpenTofu
August 1, 2024
July 24, 2024