In this blog post, we will look at how to create Synthetics uptime HTTP test in bulk using a CSV file with Splunk Observability Synthetics terraform provider.
This code requires Terraform version 0.13+.
Create a CSV file with details of uptime tests such as Test name, URL, SSL validation, frequency, locations etc. as following:
name,url,ssl_validation,frequency,scheduling_strategy,active,user_agent,locations
Google test,https://www.google.com,true,5,round_robin,true,Splunk (Default),"aws-us-east-1,aws-us-west-1"
Amazon test,https://www.amazon.com,true,5,concurrent,true,Splunk (Default),"aws-us-east-1"
The above example CSV file has following columns, please update the data in each columns as per your requirements:
Column Name |
Description |
name |
Uptime test name |
url |
Uptime test URL |
ssl_validation |
Set to true if you want to enable TLS/SSL validation, otherwise set to false |
frequency |
Specify test frequency number (in minutes) |
scheduling_strategy |
Set round_robin if you want to enable Round-robin, otherwise set concurrent |
active |
Set to true if you want to enable test, otherwise set to false |
user_agent |
Provide the User agent string you want to use, otherwise set Splunk (Default) |
locations |
Provide the list of locations in double quotes separated by comma, such as "aws-us-east-1,aws-us-west-1" or "aws-us-east-1". Here's the list of available Splunk Synthetics public locations. |
Create main.tf terraform file as following in the same folder where your CSV file is located:
terraform {
required_providers {
synthetics = {
version = "2.0.1"
source = "splunk/synthetics"
}
}
}
provider "synthetics" {
product = "observability"
realm = "REPLACE_REALM"
apikey = "REPLACE_WITH_API_TOKEN"
}
locals {
http_test_data = csvdecode(file("${path.module}/<REPLACE_WITH_CSV_FILE_NAME>.csv"))
}
resource "synthetics_create_http_check_v2" "o11y_http_check" {
for_each = { for test_data in local.http_test_data : test_data.name => test_data }
test {
active = each.value.active
frequency = each.value.frequency
location_ids = split(",",each.value.locations)
name = each.value.name
type = "http"
url = each.value.url
scheduling_strategy = each.value.scheduling_strategy
request_method = "GET"
verify_certificates = each.value.ssl_validation
user_agent = each.value.user_agent
}
}
You can modify the above terraform code as per your requirement, and data provided in CSV file.
Please note that, you will have to replace Splunk Observability realm, Splunk Observability API token and CSV file name.
Once terraform and CSV files are ready, run following commands to create HTTP uptime tests from CSV file:
Voila! You have now created uptime tests using CSV data.
If you want to delete existing uptime tests created using terraform automation, please run the following command:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.