From 6e5c3466129935ee5b98f1ba163fa534d460dcc1 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Wed, 28 Aug 2024 15:40:56 +0200 Subject: [PATCH] Add data provider for monitoring IPs (#114) --- .github/workflows/test.yml | 2 +- Makefile | 2 +- docs/data-sources/betteruptime_ip_list.md | 28 +++++++ examples/ips/README.md | 17 +++++ examples/ips/main.tf | 7 ++ examples/ips/outputs.tf | 7 ++ examples/ips/variables.tf | 15 ++++ examples/ips/versions.tf | 9 +++ internal/provider/data_ip_list.go | 93 +++++++++++++++++++++++ internal/provider/data_ip_list_test.go | 79 +++++++++++++++++++ internal/provider/provider.go | 1 + internal/provider/resource_ip_list.go | 41 ++++++++++ 12 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 docs/data-sources/betteruptime_ip_list.md create mode 100644 examples/ips/README.md create mode 100644 examples/ips/main.tf create mode 100644 examples/ips/outputs.tf create mode 100644 examples/ips/variables.tf create mode 100644 examples/ips/versions.tf create mode 100644 internal/provider/data_ip_list.go create mode 100644 internal/provider/data_ip_list_test.go create mode 100644 internal/provider/resource_ip_list.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c69335..fd7422d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: terraform-version: ["0.14", "1.0", "1.8", "latest"] - config: [examples/basic, examples/advanced, examples/on_call_calendars] + config: [examples/basic, examples/advanced, examples/ips, examples/on_call_calendars] fail-fast: false runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index c9494d8..3c94350 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ GOLANGCI_LINT := golangci-lint run --disable-all \ -E staticcheck \ -E typecheck \ -E unused -VERSION := 0.11.9 +VERSION := 0.11.10 .PHONY: test build help: diff --git a/docs/data-sources/betteruptime_ip_list.md b/docs/data-sources/betteruptime_ip_list.md new file mode 100644 index 0000000..69f7d19 --- /dev/null +++ b/docs/data-sources/betteruptime_ip_list.md @@ -0,0 +1,28 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "betteruptime_ip_list Data Source - terraform-provider-better-uptime" +subcategory: "" +description: |- + Monitoring IPs lookup. +--- + +# betteruptime_ip_list (Data Source) + +Monitoring IPs lookup. + + + + +## Schema + +### Optional + +- **filter_clusters** (List of String) The optional list of clusters used to filter the IPs. + +### Read-Only + +- **all_clusters** (List of String) The list of all clusters. +- **id** (String) The internal ID of the resource, can be ignored. +- **ips** (List of String) The list of IPs used for monitoring. + + diff --git a/examples/ips/README.md b/examples/ips/README.md new file mode 100644 index 0000000..9945fb8 --- /dev/null +++ b/examples/ips/README.md @@ -0,0 +1,17 @@ +This directory contains a sample Terraform configuration for getting all IPs used by Better Stack for Uptime monitoring. +These IPs can be used to configure resources in other providers accordingly. + +## Usage + +```shell script +git clone https://github.com/BetterStackHQ/terraform-provider-better-uptime && \ + cd terraform-provider-better-uptime/examples/ips + +echo '# See variables.tf for more. +betteruptime_api_token = "XXXXXXXXXXXXXXXXXXXXXXXX" +betteruptime_clusters = ["us"] +' > terraform.tfvars + +terraform init +terraform apply +``` diff --git a/examples/ips/main.tf b/examples/ips/main.tf new file mode 100644 index 0000000..20b019f --- /dev/null +++ b/examples/ips/main.tf @@ -0,0 +1,7 @@ +provider "betteruptime" { + api_token = var.betteruptime_api_token +} + +data "betteruptime_ip_list" "this" { + filter_clusters = var.betteruptime_clusters +} diff --git a/examples/ips/outputs.tf b/examples/ips/outputs.tf new file mode 100644 index 0000000..b7e5473 --- /dev/null +++ b/examples/ips/outputs.tf @@ -0,0 +1,7 @@ +output "monitoring_ips" { + value = data.betteruptime_ip_list.this.ips +} + +output "monitoring_clusters" { + value = data.betteruptime_ip_list.this.all_clusters +} diff --git a/examples/ips/variables.tf b/examples/ips/variables.tf new file mode 100644 index 0000000..802c21f --- /dev/null +++ b/examples/ips/variables.tf @@ -0,0 +1,15 @@ +variable "betteruptime_api_token" { + type = string + description = <