Created
February 16, 2024 11:19
-
-
Save cveld/94ee0ec00e4b4655494a517446dab7cf to your computer and use it in GitHub Desktop.
Cycle through two certs every 5 secs
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
# Ultimately we obviously increase the numbers to e.g. 6 months | |
locals { | |
plantimestamp = plantimestamp() | |
secs = format("%02d", floor(tonumber(formatdate("ss", local.plantimestamp)) / 10) * 10) | |
rounded = "${formatdate("YYYY-MM-DD", local.plantimestamp)}T${formatdate("hh:mm", local.plantimestamp)}:${local.secs}Z" | |
diff = timecmp(local.value2, local.plantimestamp) | |
s1 = local.rounded | |
value2 = timeadd(local.rounded, "5s") | |
s2 = local.diff == 1 ? timeadd(local.rounded, "-5s") : local.value2 | |
} | |
output "active_cert" { | |
#value = local.list[floor(local.timestamp_number / 5) % length(local.list)] | |
value = timecmp(local.s1, local.s2) == 1 ? "c1" : "c2" | |
} | |
resource "terraform_data" "s1" { | |
input = local.s1 | |
} | |
resource "terraform_data" "s2" { | |
input = local.s2 | |
} | |
resource "terraform_data" "c1" { | |
lifecycle { | |
replace_triggered_by = [terraform_data.s1] | |
} | |
} | |
resource "terraform_data" "c2" { | |
lifecycle { | |
replace_triggered_by = [terraform_data.s2] | |
} | |
} | |
# Output: | |
# active_cert = "c1" | |
# active_cert = "c2" | |
# alternating every 5 secs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment