Created
April 6, 2023 15:53
-
-
Save emibcn/452b47bfdacbede971ee3f0aa157ee24 to your computer and use it in GitHub Desktop.
Terraform module to change a timestamp's timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This module transforms the time variable into an | |
# RFC 3339 formated date in UTC timezone | |
locals { | |
time_ZZZZZ = formatdate( | |
"YYYY-MM-DD'T'hh:mm:ssZZZZZ", | |
var.time) | |
time_zoneless = formatdate( | |
"YYYY-MM-DD'T'hh:mm:ss", | |
var.time) | |
time_zone_sign = substr( | |
local.time_ZZZZZ, | |
length(local.time_zoneless), | |
1) | |
time_zone = substr( | |
local.time_ZZZZZ, | |
length(local.time_zoneless) + 1, | |
-1) | |
time_diff = "${ | |
replace(local.time_zone, ":", "h") | |
}m" | |
time_UTC = timeadd( | |
"${local.time_zoneless}+00:00", | |
"${ | |
local.time_zone_sign == "+" | |
? "-" | |
: "+" | |
}${local.time_diff}") | |
} | |
output "utc" { | |
description = "Time converted to UTC" | |
value = local.time_UTC | |
} | |
variable "time" { | |
description = "Time to be converted to UTC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment