From c700012b9ccb2f85f07516900789f0a20d3d34ee Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 11:08:10 +0100 Subject: [PATCH 1/7] Extended documentation to cover author and output descriptions. --- README.md | 32 ++++++++++++++++++++++++++------ outputs.tf | 12 ++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3b09c37..c21f6ff 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ # Overbuilt myip module -## What it does: +## 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). We support two providers - `curl` and `http`. `curl` is the default provider because it has better failure handling whereas `http` provider will fail a plan/apply if the endpoint doesn't respond. +## Limitations + +Neither the `curl` nor `http` providers are perfect. The `curl` provider is slightly more reliable than the `http` provider, but `curl` is missing a timeout option (for now). + ## Requirements @@ -39,14 +43,30 @@ No modules. |------|-------------|------|---------|:--------:| | [data\_provider](#input\_data\_provider) | `curl` or `http` providers are both supported - we recommend `curl` | `string` | `"curl"` | no | | [extra\_service\_urls](#input\_extra\_service\_urls) | Put your own in here if you want extra ones, this gets merged with the `service_urls` list | `list(string)` | `[]` | no | -| [service\_urls](#input\_service\_urls) | List of urls to use for getting our IP | `list(string)` |
[
"https://api.seeip.org",
"https://ipinfo.io/ip",
"https://ifconfig.co",
"https://icanhazip.com",
"https://api.ipify.org",
"https://ifconfig.me",
"https://ipecho.net/plain",
"https://ifconfig.io",
"http://eth0.me/",
"https://ident.me",
"https://ipv4.ident.me"
]
| no | +| [service\_urls](#input\_service\_urls) | List of urls to use for getting our IP | `list(string)` |
[
"https://api.seeip.org",
"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://ipv4.ident.me"
]
| no | ## Outputs | Name | Description | |------|-------------| -| [ipv4](#output\_ipv4) | n/a | -| [ipv4\_all\_matches](#output\_ipv4\_all\_matches) | n/a | -| [ipv6](#output\_ipv6) | n/a | -| [ipv6\_all\_matches](#output\_ipv6\_all\_matches) | n/a | +| [ipv4](#output\_ipv4) | The most common ipv4 myip response | +| [ipv4\_all\_matches](#output\_ipv4\_all\_matches) | List of all the ipv4 matches (informational) | +| [ipv6](#output\_ipv6) | The most common ipv6 myip response | +| [ipv6\_all\_matches](#output\_ipv6\_all\_matches) | List of all the ipv6 matches (informational) | + +## 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. \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index 81c3ce6..5023a32 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,16 +1,20 @@ output "ipv4_all_matches" { - value = local.ipv4_matches + value = local.ipv4_matches + description = "List of all the ipv4 matches (informational)" } output "ipv6_all_matches" { - value = local.ipv6_matches + value = local.ipv6_matches + description = "List of all the ipv6 matches (informational)" } output "ipv4" { - value = join("", local.ipv4_most_common_response) + value = join("", local.ipv4_most_common_response) + description = "The most common ipv4 myip response" } output "ipv6" { - value = join("", local.ipv6_most_common_response) + value = join("", local.ipv6_most_common_response) + description = "The most common ipv6 myip response" } \ No newline at end of file From 87ebed505235f98b934575cae3a147c313f9d497 Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 11:09:32 +0100 Subject: [PATCH 2/7] Reordered outputs --- outputs.tf | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/outputs.tf b/outputs.tf index 5023a32..aff2c4d 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,20 +1,19 @@ +output "ipv4" { + value = join("", local.ipv4_most_common_response) + description = "The most common ipv4 response" +} + +output "ipv6" { + value = join("", local.ipv6_most_common_response) + description = "The most common ipv6 response" +} output "ipv4_all_matches" { value = local.ipv4_matches - description = "List of all the ipv4 matches (informational)" + description = "List of all the ipv4 matches (informational/testing)" } output "ipv6_all_matches" { value = local.ipv6_matches - description = "List of all the ipv6 matches (informational)" + description = "List of all the ipv6 matches (informational/testing)" } - -output "ipv4" { - value = join("", local.ipv4_most_common_response) - description = "The most common ipv4 myip response" -} - -output "ipv6" { - value = join("", local.ipv6_most_common_response) - description = "The most common ipv6 myip response" -} \ No newline at end of file From ce3a3e4bb9b9b465e5550143e6d915daea7e7468 Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 11:09:56 +0100 Subject: [PATCH 3/7] Output descriptions. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c21f6ff..5fcaa7a 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,10 @@ No modules. | Name | Description | |------|-------------| -| [ipv4](#output\_ipv4) | The most common ipv4 myip response | -| [ipv4\_all\_matches](#output\_ipv4\_all\_matches) | List of all the ipv4 matches (informational) | -| [ipv6](#output\_ipv6) | The most common ipv6 myip response | -| [ipv6\_all\_matches](#output\_ipv6\_all\_matches) | List of all the ipv6 matches (informational) | +| [ipv4](#output\_ipv4) | The most common ipv4 response | +| [ipv4\_all\_matches](#output\_ipv4\_all\_matches) | List of all the ipv4 matches (informational/testing) | +| [ipv6](#output\_ipv6) | The most common ipv6 response | +| [ipv6\_all\_matches](#output\_ipv6\_all\_matches) | List of all the ipv6 matches (informational/testing) | ## Authors From 9abc5d0e255ca61cabb47c71a8140d2f4960a200 Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 11:33:54 +0100 Subject: [PATCH 4/7] switched to curl2 provider which includes timeout configuration --- README.md | 14 ++++++++------ main.tf | 29 ++++++++++++++++++++--------- variables.tf | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5fcaa7a..8342fdb 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ 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). -We support two providers - `curl` and `http`. `curl` is the default provider because it has better failure handling whereas `http` provider will fail a plan/apply if the endpoint doesn't respond. +We support two providers - `curl2` and `http`. `curl2` is the default provider because it has better failure handling whereas `http` provider will fail a plan/apply if the endpoint doesn't respond. ## Limitations -Neither the `curl` nor `http` providers are perfect. The `curl` provider is slightly more reliable than the `http` provider, but `curl` is missing a timeout option (for now). +Neither the `curl2` nor `http` providers are perfect. The `curl2` provider is slightly more reliable than the `http` provider. ## Requirements @@ -16,14 +16,14 @@ Neither the `curl` nor `http` providers are perfect. The `curl` provider is slig | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | ~> 1.0 | -| [curl](#requirement\_curl) | ~> 1.0.2 | +| [curl2](#requirement\_curl2) | ~> 1.6 | | [http](#requirement\_http) | ~> 3 | ## Providers | Name | Version | |------|---------| -| [curl](#provider\_curl) | 1.0.2 | +| [curl2](#provider\_curl2) | 1.6.1 | | [http](#provider\_http) | 3.4.0 | ## Modules @@ -34,15 +34,17 @@ No modules. | Name | Type | |------|------| -| [curl_curl.myip](https://registry.terraform.io/providers/anschoewe/curl/latest/docs/data-sources/curl) | data source | +| [curl2_curl2.myip](https://registry.terraform.io/providers/mehulgohil/curl2/latest/docs/data-sources/curl2) | data source | | [http_http.myip](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [data\_provider](#input\_data\_provider) | `curl` or `http` providers are both supported - we recommend `curl` | `string` | `"curl"` | no | +| [data\_provider](#input\_data\_provider) | `curl2` or `http` providers are both supported - we recommend `curl2` | `string` | `"curl2"` | no | | [extra\_service\_urls](#input\_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](#input\_request\_timeout) | Request timeout in milliseconds | `number` | `500` | no | +| [retry\_attempts](#input\_retry\_attempts) | Request retries | `number` | `0` | no | | [service\_urls](#input\_service\_urls) | List of urls to use for getting our IP | `list(string)` |
[
"https://api.seeip.org",
"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://ipv4.ident.me"
]
| no | ## Outputs diff --git a/main.tf b/main.tf index 53ac921..2dc3fe2 100644 --- a/main.tf +++ b/main.tf @@ -1,9 +1,9 @@ terraform { required_version = "~> 1.0" required_providers { - curl = { - version = "~> 1.0.2" - source = "anschoewe/curl" + curl2 = { + version = "~> 1.6" + source = "mehulgohil/curl2" } http = { version = "~> 3" @@ -12,11 +12,19 @@ terraform { } } -# curl is the default method -data "curl" "myip" { - for_each = var.data_provider == "curl" ? toset(local.service_urls) : [] - http_method = "GET" +provider "curl2" { + timeout_ms = var.request_timeout + retry { + retry_attempts = var.retry_attempts + } +} + +# curl2 is the default method +data "curl2" "myip" { + for_each = var.data_provider == "curl2" ? toset(local.service_urls) : [] uri = each.key + http_method = "GET" + } # but we can use http if you prefer @@ -24,7 +32,10 @@ data "http" "myip" { for_each = var.data_provider == "http" ? toset(local.service_urls) : [] url = each.key method = "GET" - request_timeout_ms = 500 + request_timeout_ms = var.request_timeout + retry { + attempts = var.retry_attempts + } } locals { @@ -32,7 +43,7 @@ locals { service_urls = distinct(concat(var.service_urls, var.extra_service_urls)) # build a list of responses - service_response_bodies = var.data_provider == "curl" ? values(data.curl.myip)[*].response : values(data.http.myip)[*].response_body + service_response_bodies = var.data_provider == "curl2" ? values(data.curl2.myip)[*].response.body : values(data.http.myip)[*].response_body # remunge it without whitespace as a list of strings split_output = split(",", replace(trimspace(join(",", local.service_response_bodies)), "/\\s/", "")) diff --git a/variables.tf b/variables.tf index 0891cd6..041be23 100644 --- a/variables.tf +++ b/variables.tf @@ -15,6 +15,18 @@ variable "service_urls" { description = "List of urls to use for getting our IP" } +variable "request_timeout" { + default = 500 + type = number + description = "Request timeout in milliseconds" +} + +variable "retry_attempts" { + default = 0 + type = number + description = "Request retries" +} + variable "extra_service_urls" { default = [] type = list(string) @@ -22,7 +34,7 @@ variable "extra_service_urls" { } variable "data_provider" { - default = "curl" + default = "curl2" type = string - description = "`curl` or `http` providers are both supported - we recommend `curl`" + description = "`curl2` or `http` providers are both supported - we recommend `curl2`" } \ No newline at end of file From a504e4ee005f82c136f0980aa437dacc8e240dcd Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 11:42:12 +0100 Subject: [PATCH 5/7] reorder variables --- variables.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/variables.tf b/variables.tf index 041be23..fbd3146 100644 --- a/variables.tf +++ b/variables.tf @@ -15,6 +15,12 @@ variable "service_urls" { description = "List of urls to use for getting our IP" } +variable "extra_service_urls" { + default = [] + type = list(string) + description = "Put your own in here if you want extra ones, this gets merged with the `service_urls` list" +} + variable "request_timeout" { default = 500 type = number @@ -27,12 +33,6 @@ variable "retry_attempts" { description = "Request retries" } -variable "extra_service_urls" { - default = [] - type = list(string) - description = "Put your own in here if you want extra ones, this gets merged with the `service_urls` list" -} - variable "data_provider" { default = "curl2" type = string From c59c770c46a5a113447f257fe55c9ddf8b1b1b59 Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 12:47:50 +0100 Subject: [PATCH 6/7] removing stray newline --- main.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/main.tf b/main.tf index 2dc3fe2..1812c69 100644 --- a/main.tf +++ b/main.tf @@ -24,7 +24,6 @@ data "curl2" "myip" { for_each = var.data_provider == "curl2" ? toset(local.service_urls) : [] uri = each.key http_method = "GET" - } # but we can use http if you prefer From 34af8cca90835805ccfde0b014cf440823fd15a0 Mon Sep 17 00:00:00 2001 From: Alex Trull Date: Sun, 19 Nov 2023 12:49:32 +0100 Subject: [PATCH 7/7] Readme and var updates --- README.md | 2 +- variables.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8342fdb..0d1af1c 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ We support two providers - `curl2` and `http`. `curl2` is the default provider b ## Limitations -Neither the `curl2` nor `http` providers are perfect. The `curl2` provider is slightly more reliable than the `http` provider. +Neither the `curl2` nor `http` providers are perfect. The `curl2` provider is slightly more reliable than the `http` provider. We should ideally check DNS prior to polling, or find a provider that won't poll unless dns resolves - or won't fail if it doesn't resolve. ## Requirements diff --git a/variables.tf b/variables.tf index fbd3146..40e7688 100644 --- a/variables.tf +++ b/variables.tf @@ -28,7 +28,7 @@ variable "request_timeout" { } variable "retry_attempts" { - default = 0 + default = 1 type = number description = "Request retries" }