forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provisioners: Allow provisioning over IPv6
- Loading branch information
Showing
6 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package shared | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
// IpFormat formats the IP correctly, so we don't provide IPv6 address in an IPv4 format during node communication. We return the ip parameter as is if it's an IPv4 address or a hostname. | ||
func IpFormat(ip string) string { | ||
ipObj := net.ParseIP(ip) | ||
// Return the ip/host as is if it's either a hostname or an IPv4 address. | ||
if ipObj == nil || ipObj.To4() != nil { | ||
return ip | ||
} | ||
|
||
return fmt.Sprintf("[%s]", ip) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package shared | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIpFormatting_Ipv4(t *testing.T) { | ||
formatted := IpFormat("127.0.0.1") | ||
if formatted != "127.0.0.1" { | ||
t.Fatal("expected", "127.0.0.1", "got", formatted) | ||
} | ||
} | ||
|
||
func TestIpFormatting_Hostname(t *testing.T) { | ||
formatted := IpFormat("example.com") | ||
if formatted != "example.com" { | ||
t.Fatal("expected", "example.com", "got", formatted) | ||
} | ||
} | ||
|
||
func TestIpFormatting_Ipv6(t *testing.T) { | ||
formatted := IpFormat("::1") | ||
if formatted != "[::1]" { | ||
t.Fatal("expected", "[::1]", "got", formatted) | ||
} | ||
} |
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
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
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
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