Skip to content

A terraform module to reliably get my ip (v4 and/or v6) even when some services could fail or give wrong answers or you have hashed connections.

License

Notifications You must be signed in to change notification settings

atrull/terraform-overbuilt-getmyip

Repository files navigation

Overbuilt myip module

What it does

This module polls a series of fairly well known but occasionally unreliable 'what is my ip' services. It then produces the most common response that is a valid ipv4 or ipv6 address (both outputs are separately provided).

Especially useful if you have connection hashing - the distinct matches outputs will provide a list of your current public source addresses.

Requirements

Name Version
terraform ~> 1.0
curl2 ~> 1.6
external ~> 2.3.1
http ~> 3

Providers

Name Version
curl2 1.6.1
external 2.3.5
http 3.5.0

Modules

No modules.

Resources

Name Type
curl2_curl2.myip data source
external_external.external_curl data source
http_http.myip data source

Inputs

Name Description Type Default Required
data_provider curl2 or http providers are also supported - we recommend external_curl because it handles failure better string "external_curl" no
extra_service_urls Put your own in here if you want extra ones, this gets merged with the service_urls list list(string) [] no
request_timeout Request timeout in milliseconds number 500 no
retry_attempts Request retries number 1 no
service_urls List of urls to use for getting our IP (includes both IPv4 and IPv6 services) list(string)
[
"https://ipinfo.io/ip",
"https://ifconfig.co",
"https://icanhazip.com",
"https://api.ipify.org",
"https://ifconfig.me",
"https://ipecho.net/plain",
"https://ifconfig.io",
"https://ident.me",
"https://checkip.amazonaws.com",
"https://httpbin.org/ip",
"https://myexternalip.com/raw",
"https://wtfismyip.com/text",
"https://ip.seeip.org",
"https://curlmyip.net",
"https://ipv4.icanhazip.com",
"https://ipv6.icanhazip.com",
"https://ipv6.ident.me",
"https://v6.ident.me"
]
no

Outputs

Name Description
ipv4 The most common ipv4 response
ipv4_all_matches List of all ipv4 matches (informational/testing)
ipv4_distinct_matches List of unique ipv4 matches
ipv4_frequency_map Map of IPv4 addresses to their frequency count
ipv6 The most common ipv6 response
ipv6_all_matches List of all ipv6 matches (informational/testing)
ipv6_distinct_matches List of unique ipv6 matches
ipv6_frequency_map Map of IPv6 addresses to their frequency count
service_statistics Statistics about service responses

Providers and their Limitations : An explanation.

The goal of this module is to provide a valid-enough answer even when the internet does what the internet does, which is to be flaky and broken somewhere, sometime.

Neither the curl2 nor http providers are perfectly suited to the internet since they will fail a run if the url doesn't respond and/or the url doesn't resolve. The curl2 provider is slightly more reliable than the http provider. This failure mode makes sense if it's a critical part of your terraform..

Both of curl2 and http providers are provided as a matter of them being possibly better in the future if/when they have some ignore_failure options.

Since we're aggregating results to achieve a 'most common' response it frankly shouldn't matter if one of the endpoints in the list fails to respond - we will have gathered enough data to make a good response. Let the build roll on!

As such we implement an external_curl using the external provider and a shim script external_curl.sh, which will survive a truly non-resolving non-responsive endpoint by faking the response data, which will be filtered out later by our ipv4_matches and ipv6_matches filters.

Authors

Alex Trull (firstname@lastname.org)

License

BSD-3

Inspiration

The failed builds because the myip service I had chosen wasn't working or there was a routing error in the pipeline. I owe it all to you!

Additional information for users from all ip addresses

  • I am very fond of you all.

About

A terraform module to reliably get my ip (v4 and/or v6) even when some services could fail or give wrong answers or you have hashed connections.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published