TERRAFORM PROVIDER

Prev Next

Introduction

Terraform is a popular Infrastructure-as-Code tool that can be used to quickly provision resources. With the Catchpoint Terraform provider, users can manage (Create, Read, Update, and Delete) Web, API, Transaction, DNS, SSL, BGP, Traceroute, and Ping tests with minimum configurations. To inherit sections such as Scheduling, Advanced Settings, Insights, and Alerts, simply omit the corresponding blocks.

Prerequisites

  • Terraform
  • Catchpoint account with a REST API V2 Token

Installation & Configuration

  1. Download the appropriate binary attached to the bottom of this article per your operating system.

    • Linux - terraform-provider-catchpoint
    • MacOS with M1 or M2 processor - terraform-provider-catchpoint_darwin_arm64
    • MacOS with Intel Processor - terraform-provider-catchpoint_darwin_amd64
  2. Extract the files from the downloaded zip file:

    • terraform-provider-catchpoint (Terraform provider binary)
    • main.tf (configuration file example for Object Test)
      (The additional subfolders each contain another main.tf file configured to set up another test type.)
  3. Place the binary and the desired main.tf file at terraform.d/plugins/<SOURCE HOST>/<SOURCE NAMESPACE>/<PLUGIN NAME>/<VERSION>/linux_amd64, relative to the root of the directory.
    Note: For MacOS the path name will change accordingly e.g. ~/.terraform.d/plugins/terraform-catchpoint/catchpointprovider/catchpoint/1.0.0/darwin_amd64

  4. Edit the main.tf file and modify the source host and namespace in the required_providers block to match the location where you placed the binary.
    For example, if the terraform-provider-catchpoint binary is placed in /.terraform.d/plugins/terraform-catchpoint/catchpointprovider/catchpoint/1.0.0/linux_amd64, then the required_providers block in main.tf should look like this:

terraform {
    required_providers {
        catchpoint = {
            source = "catchpoint/catchpoint" 
            version = "1.1.0"
        }
    }
}

Pleas
3. In the main.tf file add your API v2 key to the provider block.

provider "catchpoint" {api_token="8D7E2B17C339AD3EDCDD0761D29AXXXXXXXXXXXXX"}

Note: if the API key is already exported to the environment variable CATCHPOINT_API_TOKEN, you may omit this block.
4. Edit the resource block to reflect the test you want to manage or create. The table in the following section lists supported test types and their properties.
Example:

resource "web_test" "test" {
    provider=catchpoint
    division_id=1000
    product_id=15330
    test_name="catchpointTf"
    test_url="https://www.catchpoint.com"
    enable_test_data_webhook=true
    end_time="2023-09-05T04:59:00Z"
}
  1. The main.tf file also includes sample blocks for the additional test settings sections. Any of these blocks you choose to keep will override inheritance for the corresponding settings in your test configuration. Any omitted blocks will be inherited from the parent Folder/Product.

Example:

resource "web_test" "test" {
    provider=catchpoint
    monitor="object"
    division_id=1000
    product_id=15330
    test_name="catchpointTf"
    test_url="https://www.catchpoint.com"
    enable_test_data_webhook=true
    end_time="2023-09-05T04:59:00Z"
    request_settings {
        http_request_headers {
            user_agent {
                value="terraform"
            }
            accept {
                value="application/json"
                child_host_pattern="www.google.com"
            }
        }
    } 
    schedule_settings {
        frequency="60 minutes"
        node_distribution="concurrent" node_ids=[12,136]
    }
    alert_settings {
        alert_rule {
            alert_type="test failure"
            node_threshold_type="runs"
            threshold_number_of_runs=2
            threshold_percentage_of_runs=60
        }
        notification_group {
            recipient_email_ids=["recipient1@example.com"]
        }
    }
}

Supported Properties

This table lists the main properties supported for each Catchpoint test type, as well as the names of the optional settings blocks you may include. You can omit any unneeded blocks and those settings will be inherited from the parent Product/Folder. In general, the property names in the main.tf file should match the corresponding field labels in the Catchpoint Portal, but are all lower-case and use underscores (_) in place of spaces. (e.g. the Test Name property will be added to the main.tf file as "test_name")

Resource Type Configuration Settings
All (these settings apply to all resource types)
  • test_name
  • status ("active" or "inactive")
  • test_description
  • monitor (for test types that support multiple monitors)
  • provider ("catchpoint" or match configured provider name in required providers block)
  • division_id (Creating a test at the client level also require a division id. This division id can be found by following the steps mentioned in this article)
  • product_id
  • folder_id (include if test is located in a folder)
  • gateway_address_host
  • alerts_paused ("true" or "false")
  • start_date
  • end_date
  • enable_test_data_webhook ("true" or "false")
web_test Test Properties
  • simulate (for mobile, mobile playback monitors)
  • chrome_version (for chrome monitor)
Optional Blocks
  • thresholds
  • advanced_settings
  • request_settings
  • labels
  • insights
  • scheduling
  • alerts (test failure, page failure, availability, timing)
api_test Test Properties
  • script_type (selenium or javascript)
  • script
Optional Blocks
  • thresholds
  • advanced_settings
  • request_settings
  • labels
  • insights
  • scheduling
  • alerts (test failure, host failure, timing, byte length, content match, insight, requests)
transaction_test Test Properties
  • simulate (for mobile monitor)
  • chrome_version (for chrome monitor)
  • script
Optional Blocks
  • thresholds
  • advanced_settings
  • request_settings
  • labels
  • insights
  • scheduling
  • alerts (test failure, host failure, timing, insights, byte length, content match, host failure, zone data, requests)
traceroute_test Test Properties
  • test_location
Optional Blocks
  • thresholds
  • advanced_settings
  • labels
  • scheduling
  • alerts (test failure, asn, path, ping)
ping_test Test Properties
  • test_location
Optional Blocks
  • thresholds
  • advanced_settings
  • labels
  • scheduling
  • alerts (test failure, ping)
dns_test Test Properties
  • test_domain
  • dns_server (for dns direct monitor)
  • query_type
Optional Blocks
  • thresholds
  • advanced_settings
  • labels
  • scheduling
  • alerts (test failure)
bgp_test Test Properties
  • prefix
Optional Blocks
  • labels
  • alerts (test failure, asn)
ssl_test Test Properties
  • test_location
  • enforce_certificate_pinning
  • enforce_public_key_pinning
Optional Blocks
  • thresholds
  • advanced_settings
  • labels
  • scheduling
  • alerts (test failure, timing)

How To Run

  1. Create a directory with an arbitrary name.
  2. Navigate to the newly created directory.
  3. Create the main.tf file with all the blocks mentioned above. Use any of the sample main.tf files from the attached .zip file for reference.
  4. In the terminal, run terraform init to initialize the provider.
  5. Run terraform plan to see the changes to be applied.
  6. Run terraform apply to apply the plan. If Terraform Debug logs are enabled, the API response can be seen from the Catchpoint provider. The logs will indicate whether the test was created successfully.

Results

Tera.png

terraform-provider-catchpoint_darwin_arm64 (1) 2.zip

terraform-provider-catchpoint_darwin_amd64 2.zip

terraform-provider-catchpoint (1) 2(1).zip