Skip to content

Instantly share code, notes, and snippets.

@emibcn
Created April 6, 2023 15:53
Show Gist options
  • Select an option

  • Save emibcn/452b47bfdacbede971ee3f0aa157ee24 to your computer and use it in GitHub Desktop.

Select an option

Save emibcn/452b47bfdacbede971ee3f0aa157ee24 to your computer and use it in GitHub Desktop.

Revisions

  1. emibcn created this gist Apr 6, 2023.
    37 changes: 37 additions & 0 deletions time_to_utc.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # 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"
    }