Created
August 15, 2023 16:57
-
-
Save h0tw1r3/1baa1d4a5d8bcb9127d6d2b5d3e56636 to your computer and use it in GitHub Desktop.
aws region timezone fact for puppet, useful for cron offsets when system time is UTC
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
Facter.add('region_tzinfo') do | |
ec2m = Facter.value(:ec2_metadata) | |
# aws instances that have not been powercycled in 2+ years | |
# will not have region in the metadata | |
aws_zone = ec2m.dig('placement', 'availability-zone') | |
iana_tz = case aws_zone | |
when %r{^ap-southeast-1} | |
'Asia/Singapore' | |
when %r{^ap-southeast-2} | |
'Australia/Sydney' | |
when %r{^ap-southeast-3} | |
'Asia/Jakarta' | |
when %r{^ap-southeast-4} | |
'Australia/Melbourne' | |
when %r{^ca-central} | |
'Canada/Central' | |
when %r{^eu-west-1} | |
'Europe/Dublin' | |
when %r{^eu-west-2} | |
'Europe/London' | |
when %r{^eu-west-3} | |
'Europe/Paris' | |
when %r{^us-east} | |
'America/New_York' | |
when %r{^us-west} | |
'America/Los_Angeles' | |
else | |
ENV['TZ'] || 'UTC' | |
end | |
old_tz = ENV['TZ'] | |
ENV['TZ'] = iana_tz | |
data = { | |
name: iana_tz, | |
offset: Time.now.gmt_offset / 60 / 60, | |
zone: Time.now.zone, | |
} | |
ENV['TZ'] = old_tz | |
setcode do | |
data | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment