From 4f7d3ed2be6847ff85093b098fa99a9bfb030ed3 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Wed, 21 Jan 2026 13:38:49 +0000 Subject: [PATCH] feat(E2E Tests): add comprehensive tests for various monitor types with steps and basic configurations --- .../tests/35-monitor-with-steps/main.tf | 640 ++++++++++++++++++ .../tests/35-monitor-with-steps/variables.tf | 15 + .../tests/35-monitor-with-steps/verify.sh | 115 ++++ .../tests/36-monitor-types-basic/main.tf | 222 ++++++ .../tests/36-monitor-types-basic/variables.tf | 15 + .../tests/36-monitor-types-basic/verify.sh | 85 +++ 6 files changed, 1092 insertions(+) create mode 100644 E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/main.tf create mode 100644 E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/variables.tf create mode 100755 E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/verify.sh create mode 100644 E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/main.tf create mode 100644 E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/variables.tf create mode 100755 E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/verify.sh diff --git a/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/main.tf b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/main.tf new file mode 100644 index 0000000000..d15255ee07 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/main.tf @@ -0,0 +1,640 @@ +terraform { + required_providers { + oneuptime = { + source = "oneuptime/oneuptime" + version = "1.0.0" + } + } +} + +provider "oneuptime" { + oneuptime_url = var.oneuptime_url + api_key = var.api_key +} + +# Test: Monitor Types with Monitor Steps +# +# This test validates creating different monitor types with proper monitor_steps: +# - Website Monitor with HTTP checks +# - API Monitor with request headers and body +# - Ping Monitor with hostname destination +# - Port Monitor with specific port +# - SSL Certificate Monitor +# - IP Monitor + +locals { + timestamp = formatdate("YYYYMMDDhhmmss", timestamp()) +} + +# Create monitor statuses for criteria +resource "oneuptime_monitor_status" "operational" { + project_id = var.project_id + name = "TF Operational ${local.timestamp}" + description = "Monitor is operational" + color = "#2ecc71" + priority = 1 + is_operational_state = true + + lifecycle { + ignore_changes = [name] + } +} + +resource "oneuptime_monitor_status" "degraded" { + project_id = var.project_id + name = "TF Degraded ${local.timestamp}" + description = "Monitor is degraded" + color = "#f39c12" + priority = 2 + is_operational_state = false + + lifecycle { + ignore_changes = [name] + } +} + +resource "oneuptime_monitor_status" "offline" { + project_id = var.project_id + name = "TF Offline ${local.timestamp}" + description = "Monitor is offline" + color = "#e74c3c" + priority = 3 + is_operational_state = false + + lifecycle { + ignore_changes = [name] + } +} + +# ============================================================================= +# Test Case 1: Website Monitor with Monitor Steps +# ============================================================================= +resource "oneuptime_monitor" "website" { + project_id = var.project_id + name = "TF Website Monitor ${local.timestamp}" + description = "Website monitor with URL destination and response criteria" + monitor_type = "Website" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-website-1" + monitorDestination = { + _type = "URL" + value = "https://example.com" + } + requestType = "GET" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-online" + name = "Online" + description = "Check if website is online" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "True" + } + }, + { + _type = "CriteriaFilter" + value = { + checkOn = "Response Status Code" + filterType = "Equal To" + value = "200" + } + } + ] + incidents = [] + alerts = [] + } + }, + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-offline" + name = "Offline" + description = "Check if website is offline" + filterCondition = "Any" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.offline.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "False" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational, oneuptime_monitor_status.offline] +} + +# ============================================================================= +# Test Case 2: API Monitor with Headers and Body +# ============================================================================= +resource "oneuptime_monitor" "api" { + project_id = var.project_id + name = "TF API Monitor ${local.timestamp}" + description = "API monitor with POST request, headers, and body" + monitor_type = "API" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-api-1" + monitorDestination = { + _type = "URL" + value = "https://httpbin.org/post" + } + requestType = "POST" + requestHeaders = { + "Content-Type" = "application/json" + "Accept" = "application/json" + "X-Custom-Header" = "test-value" + } + requestBody = "{\"test\": \"data\"}" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-api-success" + name = "API Success" + description = "API returns success response" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "True" + } + }, + { + _type = "CriteriaFilter" + value = { + checkOn = "Response Status Code" + filterType = "Equal To" + value = "200" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational] +} + +# ============================================================================= +# Test Case 3: Ping Monitor +# ============================================================================= +resource "oneuptime_monitor" "ping" { + project_id = var.project_id + name = "TF Ping Monitor ${local.timestamp}" + description = "Ping monitor with hostname destination" + monitor_type = "Ping" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-ping-1" + monitorDestination = { + _type = "Hostname" + value = "google.com" + } + requestType = "GET" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-ping-online" + name = "Ping Success" + description = "Host responds to ping" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "True" + } + } + ] + incidents = [] + alerts = [] + } + }, + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-ping-offline" + name = "Ping Failure" + description = "Host does not respond" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.offline.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "False" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational, oneuptime_monitor_status.offline] +} + +# ============================================================================= +# Test Case 4: Port Monitor +# ============================================================================= +resource "oneuptime_monitor" "port" { + project_id = var.project_id + name = "TF Port Monitor ${local.timestamp}" + description = "Port monitor checking HTTPS port" + monitor_type = "Port" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-port-1" + monitorDestination = { + _type = "Hostname" + value = "google.com" + } + monitorDestinationPort = { + _type = "Port" + value = 443 + } + requestType = "GET" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-port-open" + name = "Port Open" + description = "Port is accepting connections" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "True" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational] +} + +# ============================================================================= +# Test Case 5: SSL Certificate Monitor +# ============================================================================= +resource "oneuptime_monitor" "ssl" { + project_id = var.project_id + name = "TF SSL Certificate Monitor ${local.timestamp}" + description = "SSL certificate monitor checking certificate validity" + monitor_type = "SSL Certificate" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-ssl-1" + monitorDestination = { + _type = "URL" + value = "https://google.com" + } + requestType = "GET" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-ssl-valid" + name = "Certificate Valid" + description = "SSL certificate is valid" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Valid Certificate" + filterType = "True" + } + } + ] + incidents = [] + alerts = [] + } + }, + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-ssl-expiring" + name = "Certificate Expiring Soon" + description = "Certificate expires within 30 days" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.degraded.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Expires In Days" + filterType = "Less Than" + value = "30" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational, oneuptime_monitor_status.degraded] +} + +# ============================================================================= +# Test Case 6: IP Monitor +# ============================================================================= +resource "oneuptime_monitor" "ip" { + project_id = var.project_id + name = "TF IP Monitor ${local.timestamp}" + description = "IP monitor checking connectivity" + monitor_type = "IP" + + monitor_steps = jsonencode({ + _type = "MonitorSteps" + value = { + monitorStepsInstanceArray = [ + { + _type = "MonitorStep" + value = { + id = "step-ip-1" + monitorDestination = { + _type = "IP" + value = "8.8.8.8" + } + requestType = "GET" + monitorCriteria = { + _type = "MonitorCriteria" + value = { + monitorCriteriaInstanceArray = [ + { + _type = "MonitorCriteriaInstance" + value = { + id = "criteria-ip-online" + name = "IP Reachable" + description = "IP address is reachable" + filterCondition = "All" + changeMonitorStatus = true + createIncidents = false + createAlerts = false + monitorStatusId = oneuptime_monitor_status.operational.id + filters = [ + { + _type = "CriteriaFilter" + value = { + checkOn = "Is Online" + filterType = "True" + } + } + ] + incidents = [] + alerts = [] + } + } + ] + } + } + } + } + ] + } + }) + + lifecycle { + ignore_changes = [name, monitor_steps] + } + + depends_on = [oneuptime_monitor_status.operational] +} + +# ============================================================================= +# Outputs +# ============================================================================= +output "website_monitor_id" { + value = oneuptime_monitor.website.id + description = "Website monitor ID" +} + +output "website_monitor_type" { + value = oneuptime_monitor.website.monitor_type + description = "Website monitor type" +} + +output "api_monitor_id" { + value = oneuptime_monitor.api.id + description = "API monitor ID" +} + +output "api_monitor_type" { + value = oneuptime_monitor.api.monitor_type + description = "API monitor type" +} + +output "ping_monitor_id" { + value = oneuptime_monitor.ping.id + description = "Ping monitor ID" +} + +output "ping_monitor_type" { + value = oneuptime_monitor.ping.monitor_type + description = "Ping monitor type" +} + +output "port_monitor_id" { + value = oneuptime_monitor.port.id + description = "Port monitor ID" +} + +output "port_monitor_type" { + value = oneuptime_monitor.port.monitor_type + description = "Port monitor type" +} + +output "ssl_monitor_id" { + value = oneuptime_monitor.ssl.id + description = "SSL certificate monitor ID" +} + +output "ssl_monitor_type" { + value = oneuptime_monitor.ssl.monitor_type + description = "SSL certificate monitor type" +} + +output "ip_monitor_id" { + value = oneuptime_monitor.ip.id + description = "IP monitor ID" +} + +output "ip_monitor_type" { + value = oneuptime_monitor.ip.monitor_type + description = "IP monitor type" +} + +output "operational_status_id" { + value = oneuptime_monitor_status.operational.id + description = "Operational status ID" +} + +output "degraded_status_id" { + value = oneuptime_monitor_status.degraded.id + description = "Degraded status ID" +} + +output "offline_status_id" { + value = oneuptime_monitor_status.offline.id + description = "Offline status ID" +} diff --git a/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/variables.tf b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/variables.tf new file mode 100644 index 0000000000..3817cd77a2 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/variables.tf @@ -0,0 +1,15 @@ +variable "oneuptime_url" { + type = string + description = "OneUptime API URL" +} + +variable "api_key" { + type = string + description = "OneUptime API Key" + sensitive = true +} + +variable "project_id" { + type = string + description = "OneUptime Project ID" +} diff --git a/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/verify.sh b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/verify.sh new file mode 100755 index 0000000000..fafb902681 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/35-monitor-with-steps/verify.sh @@ -0,0 +1,115 @@ +#!/bin/bash +set -e + +echo "=== Monitor Types with Steps Test Verification ===" + +# Get outputs +WEBSITE_ID=$(terraform output -raw website_monitor_id 2>/dev/null || echo "") +WEBSITE_TYPE=$(terraform output -raw website_monitor_type 2>/dev/null || echo "") +API_ID=$(terraform output -raw api_monitor_id 2>/dev/null || echo "") +API_TYPE=$(terraform output -raw api_monitor_type 2>/dev/null || echo "") +PING_ID=$(terraform output -raw ping_monitor_id 2>/dev/null || echo "") +PING_TYPE=$(terraform output -raw ping_monitor_type 2>/dev/null || echo "") +PORT_ID=$(terraform output -raw port_monitor_id 2>/dev/null || echo "") +PORT_TYPE=$(terraform output -raw port_monitor_type 2>/dev/null || echo "") +SSL_ID=$(terraform output -raw ssl_monitor_id 2>/dev/null || echo "") +SSL_TYPE=$(terraform output -raw ssl_monitor_type 2>/dev/null || echo "") +IP_ID=$(terraform output -raw ip_monitor_id 2>/dev/null || echo "") +IP_TYPE=$(terraform output -raw ip_monitor_type 2>/dev/null || echo "") + +echo "" +echo "Website Monitor: ID=$WEBSITE_ID, Type=$WEBSITE_TYPE" +echo "API Monitor: ID=$API_ID, Type=$API_TYPE" +echo "Ping Monitor: ID=$PING_ID, Type=$PING_TYPE" +echo "Port Monitor: ID=$PORT_ID, Type=$PORT_TYPE" +echo "SSL Monitor: ID=$SSL_ID, Type=$SSL_TYPE" +echo "IP Monitor: ID=$IP_ID, Type=$IP_TYPE" + +# Verify all monitors created +ERRORS=0 + +if [ -z "$WEBSITE_ID" ]; then + echo "ERROR: Website monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$WEBSITE_TYPE" != "Website" ]; then + echo "ERROR: Website monitor type mismatch. Expected 'Website', got '$WEBSITE_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ -z "$API_ID" ]; then + echo "ERROR: API monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$API_TYPE" != "API" ]; then + echo "ERROR: API monitor type mismatch. Expected 'API', got '$API_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ -z "$PING_ID" ]; then + echo "ERROR: Ping monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$PING_TYPE" != "Ping" ]; then + echo "ERROR: Ping monitor type mismatch. Expected 'Ping', got '$PING_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ -z "$PORT_ID" ]; then + echo "ERROR: Port monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$PORT_TYPE" != "Port" ]; then + echo "ERROR: Port monitor type mismatch. Expected 'Port', got '$PORT_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ -z "$SSL_ID" ]; then + echo "ERROR: SSL monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$SSL_TYPE" != "SSL Certificate" ]; then + echo "ERROR: SSL monitor type mismatch. Expected 'SSL Certificate', got '$SSL_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ -z "$IP_ID" ]; then + echo "ERROR: IP monitor not created" + ERRORS=$((ERRORS + 1)) +fi + +if [ "$IP_TYPE" != "IP" ]; then + echo "ERROR: IP monitor type mismatch. Expected 'IP', got '$IP_TYPE'" + ERRORS=$((ERRORS + 1)) +fi + +if [ $ERRORS -gt 0 ]; then + echo "" + echo "FAILED: $ERRORS errors found" + exit 1 +fi + +echo "" +echo "=== Verifying idempotency ===" +PLAN_OUTPUT=$(terraform plan -detailed-exitcode 2>&1) || PLAN_EXIT_CODE=$? +PLAN_EXIT_CODE=${PLAN_EXIT_CODE:-0} + +if [ "$PLAN_EXIT_CODE" -eq 0 ]; then + echo "SUCCESS: No changes detected - idempotency test PASSED" +elif [ "$PLAN_EXIT_CODE" -eq 2 ]; then + echo "WARNING: Changes detected after apply (may be expected for computed fields)" + echo "Plan output:" + echo "$PLAN_OUTPUT" + # Don't fail on idempotency for this test since monitor_steps is complex +else + echo "ERROR: terraform plan failed" + exit 1 +fi + +echo "" +echo "=== Monitor Types with Steps Test PASSED ===" diff --git a/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/main.tf b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/main.tf new file mode 100644 index 0000000000..d2016df9df --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/main.tf @@ -0,0 +1,222 @@ +terraform { + required_providers { + oneuptime = { + source = "oneuptime/oneuptime" + version = "1.0.0" + } + } +} + +provider "oneuptime" { + oneuptime_url = var.oneuptime_url + api_key = var.api_key +} + +# Test: Basic Monitor Types (without explicit monitor_steps) +# +# This test validates creating different monitor types relying on server defaults: +# - Website Monitor +# - API Monitor +# - Ping Monitor +# - Port Monitor +# - SSL Certificate Monitor +# - IP Monitor + +locals { + timestamp = formatdate("YYYYMMDDhhmmss", timestamp()) +} + +# ============================================================================= +# Test Case 1: Website Monitor +# ============================================================================= +resource "oneuptime_monitor" "website" { + project_id = var.project_id + name = "TF Website Basic ${local.timestamp}" + description = "Basic website monitor" + monitor_type = "Website" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 2: API Monitor +# ============================================================================= +resource "oneuptime_monitor" "api" { + project_id = var.project_id + name = "TF API Basic ${local.timestamp}" + description = "Basic API monitor" + monitor_type = "API" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 3: Ping Monitor +# ============================================================================= +resource "oneuptime_monitor" "ping" { + project_id = var.project_id + name = "TF Ping Basic ${local.timestamp}" + description = "Basic ping monitor" + monitor_type = "Ping" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 4: Port Monitor +# ============================================================================= +resource "oneuptime_monitor" "port" { + project_id = var.project_id + name = "TF Port Basic ${local.timestamp}" + description = "Basic port monitor" + monitor_type = "Port" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 5: SSL Certificate Monitor +# ============================================================================= +resource "oneuptime_monitor" "ssl" { + project_id = var.project_id + name = "TF SSL Basic ${local.timestamp}" + description = "Basic SSL certificate monitor" + monitor_type = "SSL Certificate" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 6: IP Monitor +# ============================================================================= +resource "oneuptime_monitor" "ip" { + project_id = var.project_id + name = "TF IP Basic ${local.timestamp}" + description = "Basic IP monitor" + monitor_type = "IP" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 7: Incoming Request Monitor (Heartbeat) +# ============================================================================= +resource "oneuptime_monitor" "incoming_request" { + project_id = var.project_id + name = "TF Incoming Request Basic ${local.timestamp}" + description = "Basic incoming request (heartbeat) monitor" + monitor_type = "Incoming Request" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Test Case 8: Server Monitor +# ============================================================================= +resource "oneuptime_monitor" "server" { + project_id = var.project_id + name = "TF Server Basic ${local.timestamp}" + description = "Basic server monitor" + monitor_type = "Server" + + lifecycle { + ignore_changes = [name, monitor_steps] + } +} + +# ============================================================================= +# Outputs +# ============================================================================= +output "website_monitor_id" { + value = oneuptime_monitor.website.id + description = "Website monitor ID" +} + +output "website_monitor_type" { + value = oneuptime_monitor.website.monitor_type + description = "Website monitor type" +} + +output "api_monitor_id" { + value = oneuptime_monitor.api.id + description = "API monitor ID" +} + +output "api_monitor_type" { + value = oneuptime_monitor.api.monitor_type + description = "API monitor type" +} + +output "ping_monitor_id" { + value = oneuptime_monitor.ping.id + description = "Ping monitor ID" +} + +output "ping_monitor_type" { + value = oneuptime_monitor.ping.monitor_type + description = "Ping monitor type" +} + +output "port_monitor_id" { + value = oneuptime_monitor.port.id + description = "Port monitor ID" +} + +output "port_monitor_type" { + value = oneuptime_monitor.port.monitor_type + description = "Port monitor type" +} + +output "ssl_monitor_id" { + value = oneuptime_monitor.ssl.id + description = "SSL certificate monitor ID" +} + +output "ssl_monitor_type" { + value = oneuptime_monitor.ssl.monitor_type + description = "SSL certificate monitor type" +} + +output "ip_monitor_id" { + value = oneuptime_monitor.ip.id + description = "IP monitor ID" +} + +output "ip_monitor_type" { + value = oneuptime_monitor.ip.monitor_type + description = "IP monitor type" +} + +output "incoming_request_monitor_id" { + value = oneuptime_monitor.incoming_request.id + description = "Incoming request monitor ID" +} + +output "incoming_request_monitor_type" { + value = oneuptime_monitor.incoming_request.monitor_type + description = "Incoming request monitor type" +} + +output "server_monitor_id" { + value = oneuptime_monitor.server.id + description = "Server monitor ID" +} + +output "server_monitor_type" { + value = oneuptime_monitor.server.monitor_type + description = "Server monitor type" +} diff --git a/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/variables.tf b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/variables.tf new file mode 100644 index 0000000000..3817cd77a2 --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/variables.tf @@ -0,0 +1,15 @@ +variable "oneuptime_url" { + type = string + description = "OneUptime API URL" +} + +variable "api_key" { + type = string + description = "OneUptime API Key" + sensitive = true +} + +variable "project_id" { + type = string + description = "OneUptime Project ID" +} diff --git a/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/verify.sh b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/verify.sh new file mode 100755 index 0000000000..041469f25f --- /dev/null +++ b/E2E/Terraform/e2e-tests/tests/36-monitor-types-basic/verify.sh @@ -0,0 +1,85 @@ +#!/bin/bash +set -e + +echo "=== Basic Monitor Types Test Verification ===" + +# Get outputs +WEBSITE_ID=$(terraform output -raw website_monitor_id 2>/dev/null || echo "") +WEBSITE_TYPE=$(terraform output -raw website_monitor_type 2>/dev/null || echo "") +API_ID=$(terraform output -raw api_monitor_id 2>/dev/null || echo "") +API_TYPE=$(terraform output -raw api_monitor_type 2>/dev/null || echo "") +PING_ID=$(terraform output -raw ping_monitor_id 2>/dev/null || echo "") +PING_TYPE=$(terraform output -raw ping_monitor_type 2>/dev/null || echo "") +PORT_ID=$(terraform output -raw port_monitor_id 2>/dev/null || echo "") +PORT_TYPE=$(terraform output -raw port_monitor_type 2>/dev/null || echo "") +SSL_ID=$(terraform output -raw ssl_monitor_id 2>/dev/null || echo "") +SSL_TYPE=$(terraform output -raw ssl_monitor_type 2>/dev/null || echo "") +IP_ID=$(terraform output -raw ip_monitor_id 2>/dev/null || echo "") +IP_TYPE=$(terraform output -raw ip_monitor_type 2>/dev/null || echo "") +INCOMING_REQUEST_ID=$(terraform output -raw incoming_request_monitor_id 2>/dev/null || echo "") +INCOMING_REQUEST_TYPE=$(terraform output -raw incoming_request_monitor_type 2>/dev/null || echo "") +SERVER_ID=$(terraform output -raw server_monitor_id 2>/dev/null || echo "") +SERVER_TYPE=$(terraform output -raw server_monitor_type 2>/dev/null || echo "") + +echo "" +echo "Monitor Types Created:" +echo " Website: ID=$WEBSITE_ID, Type=$WEBSITE_TYPE" +echo " API: ID=$API_ID, Type=$API_TYPE" +echo " Ping: ID=$PING_ID, Type=$PING_TYPE" +echo " Port: ID=$PORT_ID, Type=$PORT_TYPE" +echo " SSL Certificate: ID=$SSL_ID, Type=$SSL_TYPE" +echo " IP: ID=$IP_ID, Type=$IP_TYPE" +echo " Incoming Request: ID=$INCOMING_REQUEST_ID, Type=$INCOMING_REQUEST_TYPE" +echo " Server: ID=$SERVER_ID, Type=$SERVER_TYPE" + +# Verify all monitors created +ERRORS=0 + +declare -A MONITORS=( + ["Website"]="$WEBSITE_ID:$WEBSITE_TYPE:Website" + ["API"]="$API_ID:$API_TYPE:API" + ["Ping"]="$PING_ID:$PING_TYPE:Ping" + ["Port"]="$PORT_ID:$PORT_TYPE:Port" + ["SSL Certificate"]="$SSL_ID:$SSL_TYPE:SSL Certificate" + ["IP"]="$IP_ID:$IP_TYPE:IP" + ["Incoming Request"]="$INCOMING_REQUEST_ID:$INCOMING_REQUEST_TYPE:Incoming Request" + ["Server"]="$SERVER_ID:$SERVER_TYPE:Server" +) + +for NAME in "${!MONITORS[@]}"; do + IFS=':' read -r ID TYPE EXPECTED <<< "${MONITORS[$NAME]}" + + if [ -z "$ID" ]; then + echo "ERROR: $NAME monitor not created" + ERRORS=$((ERRORS + 1)) + fi + + if [ "$TYPE" != "$EXPECTED" ]; then + echo "ERROR: $NAME monitor type mismatch. Expected '$EXPECTED', got '$TYPE'" + ERRORS=$((ERRORS + 1)) + fi +done + +if [ $ERRORS -gt 0 ]; then + echo "" + echo "FAILED: $ERRORS errors found" + exit 1 +fi + +echo "" +echo "=== Verifying idempotency ===" +PLAN_OUTPUT=$(terraform plan -detailed-exitcode 2>&1) || PLAN_EXIT_CODE=$? +PLAN_EXIT_CODE=${PLAN_EXIT_CODE:-0} + +if [ "$PLAN_EXIT_CODE" -eq 0 ]; then + echo "SUCCESS: No changes detected - idempotency test PASSED" +elif [ "$PLAN_EXIT_CODE" -eq 2 ]; then + echo "INFO: Changes detected (may be expected for server-computed fields)" + # Don't fail - monitor_steps changes are expected +else + echo "ERROR: terraform plan failed" + exit 1 +fi + +echo "" +echo "=== Basic Monitor Types Test PASSED ==="