Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeroenhabets opened this issue Feb 5, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@jeroenhabets
Copy link

jeroenhabets commented Feb 5, 2023

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 #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

@simaotwx
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants