Skip to content

Commit

Permalink
IPv6 url processing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bczoma committed Mar 4, 2024
1 parent 9edacc5 commit 63acdb2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/gen-template/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
locals {
tls = startswith(lower(var.url), "https:")
slashSplit = split("/", var.url)
isIpV6HostPort = length(split("]", local.slashSplit[2])) == 2
hostPortSplit = local.isIpV6HostPort ? split("]:", trimprefix(local.slashSplit[2], "[")) : split(":", local.slashSplit[2])
isIpV6HostWithPort = length(split("]", local.slashSplit[2])) == 2
isIpV6NoPort = local.isIpV6HostWithPort ? false : length(split(":", local.slashSplit[2])) > 2
address = local.isIpV6NoPort ? join(local.slashSplit[2], ["[", "]"]) : local.slashSplit[2]
hostPortSplit = local.isIpV6HostWithPort || local.isIpV6NoPort ? split("]:", trimprefix(local.address, "[")) : split(":", local.address)
host = trimsuffix(local.hostPortSplit[0], "]")
port = length(local.hostPortSplit) == 2 ? tonumber(local.hostPortSplit[1]) : (local.tls ? 443 : 80)
path = "/${join("/", slice(local.slashSplit, 3, length(local.slashSplit)))}"
Expand Down

0 comments on commit 63acdb2

Please sign in to comment.