BetterStackHQ/terraform-provider-better-uptime

Feature: add data blocks for ip ranges

Closed this issue · 5 comments

I currently have terraform building my firewall rules, which pulls in needed information through terraform for the different providers I use. It would be great if BetterStack exposed it's ip ranges via a terraform data source.

For example, see cloudflare's ip_ranges: https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/data-sources/ip_ranges.html

Ideally some of the static data presented on this page would be useful:
https://betterstack.com/docs/uptime/frequently-asked-questions/#what-ips-does-better-uptime-use

adikus commented

@jacobhuck Thanks for the suggestion!

We already have a machine readable list of the IPs here: https://uptime.betterstack.com/ips.txt
Let us know if that's something you could work with or would still prefer to do this using Terraform.

@adikus I can definitely use the list, but terraform would work even better for a couple of reasons:

  1. Terraform doesn't make files part of the dependency graph, so when the values in the file change you have to manually "taint" or "replace" the resource, and
  2. End users have to manually download the file and keep a local copy, which means it can get out of sync without the user knowing it

If it was a data endpoint, then BetterStack could maintain the file without any end user intervention, and terraform would "just know" it needed to rebuild the resources using the data because it would then be part of the dependency graph.

Also it would be great if the data structure returned was not just a flat list but instead had some metadata about which region the IP belonged it. For example when you only expect traffic from the US and only want to allowlist the US endpoints for the checks.

Hello @jacobhuck,

if you still want to use IPs of Better Stack's monitors, you can just use the http provider to get always up-to-date list of IPs without the need of extra provider:

data "http" "uptime_ips" {
  url = "https://uptime.betterstack.com/ips.txt"
}
output "uptime_ips" {
  value = split("\n", data.http.uptime_ips.response_body)
}

Hello @jacobhuck, @codeflows, and @peter-hippo,

We've just released a new version of our Terraform provider including betteruptime_ip_list data provider, which you can use to get all IPs - optionally filtered by cluster.

Hope this helps! 🙌 Thanks again for the suggestion, @jacobhuck!

data "betteruptime_ip_list" "this" {
  filter_clusters = ["eu","us"] # can be omitted for all clusters
}

output "monitoring_ips" {
  value = data.betteruptime_ip_list.this.ips
}

output "all_monitoring_clusters" {
  value = data.betteruptime_ip_list.this.all_clusters
}