terraform-provider-time icon indicating copy to clipboard operation
terraform-provider-time copied to clipboard

New time_zone argument for time_static (Time Zone and Daylight Savings support)

Open jeroenhabets opened this issue 2 years ago • 1 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v1.3.7 on darwin_amd64

Description

Like https://github.com/hashicorp/terraform-provider-time/issues/33 adding time zone support including daylight savings changes would be greatly appreciated.

I am aware of using the the timeadd() and formatdate() functions route, but AFAICT you're hardcoding the time zone offset this way and thus it requires manual intervention around daylight savings. Fully aware of the intricacies around time and time zones, I'd only suggest an approach using existing libraries:

One way about it would be to require locations and utilize Go's standard time zone support: https://pkg.go.dev/time#LoadLocation

Though I'd prefer to be able to support timezone abbreviations by depending on https://pkg.go.dev/github.com/tkuchiki/go-timezone.

Just like with time_rotating the daylight savings change would only occur when Terraform is executed, meaning there will be drift between the time_static timestamp and actual daylight savings.

New or Affected Resource(s)

  • time_static would get a new time_zone optional argument Nice to have:
  • time_offset
  • time_rotating

Potential Terraform Configuration

resource "time_static" "schedule_backup_time" {
  time_zone = "CET"
}

locals {
  schedule_backup_hour = time_static.schedule_backup_time.hour
}

# cron(15 ${local.schedule_backup_hour} ? * * *) ...

References

  • https://github.com/hashicorp/terraform-provider-time/issues/33
  • https://stackoverflow.com/questions/65094677/terraform-setting-time-with-timezone
  • https://pkg.go.dev/time#LoadLocation
  • https://pkg.go.dev/github.com/tkuchiki/go-timezone

jeroenhabets avatar Feb 05 '23 14:02 jeroenhabets

I find the timeadd()+formatdate() workaround to be very problematic due to time zones changing all the time, daylight savings not necessarily being the same across time zones (some don't have it at all, or just in some years). Additionally, the current timezone may not be suitable to calculate a different timezone. I am very much for implementing a way that uses tzdata or some other battle-tested standard under the hood.

simaotwx avatar Aug 19 '24 09:08 simaotwx